[clang-tools-extra] r352049 - [clangd] Clean the cache of file statuses on vscode-clangd when clangd crashes.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 24 06:25:53 PST 2019


Author: hokein
Date: Thu Jan 24 06:25:53 2019
New Revision: 352049

URL: http://llvm.org/viewvc/llvm-project?rev=352049&view=rev
Log:
[clangd] Clean the cache of file statuses on vscode-clangd when clangd crashes.

Summary:
Clear the cached file statuses, otherwise we will leave some garbage texts on
the status bar when clangd crashes.

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D56540

Modified:
    clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts?rev=352049&r1=352048&r2=352049&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts Thu Jan 24 06:25:53 2019
@@ -40,6 +40,11 @@ class FileStatus {
         this.statusBarItem.show();
     }
 
+    clear() {
+        this.statuses.clear();
+        this.statusBarItem.hide();
+    }
+
     dispose() {
         this.statusBarItem.dispose();
     }
@@ -112,9 +117,16 @@ export function activate(context: vscode
     context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(() => {
         status.updateStatus();
     }));
-    clangdClient.onReady().then(() => {
-        clangdClient.onNotification(
-            'textDocument/clangd.fileStatus',
-            (fileStatus) => { status.onFileUpdated(fileStatus); });
-    })
+    clangdClient.onDidChangeState(
+        ({ newState }) => {
+            if (newState == vscodelc.State.Running) {
+                // clangd starts or restarts after crash.
+                clangdClient.onNotification(
+                    'textDocument/clangd.fileStatus',
+                    (fileStatus) => { status.onFileUpdated(fileStatus); });
+            } else if (newState == vscodelc.State.Stopped) {
+                // Clear all cached statuses when clangd crashes.
+                status.clear();
+            }
+        })
 }




More information about the cfe-commits mailing list