[PATCH] D67165: [clangd][vscode] Make SemanticHighlightingFeature more self-contained.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 4 07:21:28 PDT 2019


hokein updated this revision to Diff 218691.
hokein added a comment.

Update the patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67165/new/

https://reviews.llvm.org/D67165

Files:
  clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
  clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts


Index: clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===================================================================
--- clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -44,7 +44,7 @@
 
 // Language server push notification providing the semantic highlighting
 // information for a text document.
-export const NotificationType =
+const NotificationType =
     new vscodelc.NotificationType<SemanticHighlightingParams, void>(
         'textDocument/semanticHighlighting');
 
@@ -58,6 +58,11 @@
   highlighter: Highlighter;
   // Any disposables that should be cleaned up when clangd crashes.
   private subscriptions: vscode.Disposable[] = [];
+  private clangdClient: vscodelc.BaseLanguageClient;
+
+  constructor(client: vscodelc.BaseLanguageClient) {
+    this.clangdClient = client;
+  }
   fillClientCapabilities(capabilities: vscodelc.ClientCapabilities) {
     // Extend the ClientCapabilities type and add semantic highlighting
     // capability to the object.
@@ -78,6 +83,12 @@
 
   initialize(capabilities: vscodelc.ServerCapabilities,
              documentSelector: vscodelc.DocumentSelector|undefined) {
+    // Dispose resources everytime we get initialized, e.g. first launch or
+    // recover from clangd crashes.
+    this.dispose();
+    // Register the handler to handle semantic highlighting notification.
+    this.clangdClient.onNotification(NotificationType,
+                                     this.handleNotification.bind(this));
     // The semantic highlighting capability information is in the capabilities
     // object but to access the data we must first extend the ServerCapabilities
     // type.
Index: clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
===================================================================
--- clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
@@ -110,7 +110,7 @@
   const clangdClient = new ClangdLanguageClient('Clang Language Server',
                                                 serverOptions, clientOptions);
   const semanticHighlightingFeature =
-      new semanticHighlighting.SemanticHighlightingFeature();
+      new semanticHighlighting.SemanticHighlightingFeature(clangdClient);
   context.subscriptions.push(
       vscode.Disposable.from(semanticHighlightingFeature));
   clangdClient.registerFeature(semanticHighlightingFeature);
@@ -144,14 +144,9 @@
       clangdClient.onNotification(
           'textDocument/clangd.fileStatus',
           (fileStatus) => { status.onFileUpdated(fileStatus); });
-      clangdClient.onNotification(
-          semanticHighlighting.NotificationType,
-          semanticHighlightingFeature.handleNotification.bind(
-              semanticHighlightingFeature));
     } else if (newState == vscodelc.State.Stopped) {
       // Clear all cached statuses when clangd crashes.
       status.clear();
-      semanticHighlightingFeature.dispose();
     }
   }));
   // An empty place holder for the activate command, otherwise we'll get an


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67165.218691.patch
Type: text/x-patch
Size: 3198 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190904/40853a2b/attachment-0001.bin>


More information about the cfe-commits mailing list