[clang-tools-extra] r371036 - [clangd][vscode] Make SemanticHighlightingFeature more self-contained.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 5 02:14:04 PDT 2019


Author: hokein
Date: Thu Sep  5 02:14:04 2019
New Revision: 371036

URL: http://llvm.org/viewvc/llvm-project?rev=371036&view=rev
Log:
[clangd][vscode] Make SemanticHighlightingFeature more self-contained.

Summary:
so that we don't have too many usage from the client side (just a single
occurrance for register), this also aligns with how other builtin feature
being implemented in vscode.

Reviewers: ilya-biryukov

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

Tags: #clang

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

Modified:
    clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
    clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.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=371036&r1=371035&r2=371036&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 Sep  5 02:14:04 2019
@@ -110,7 +110,8 @@ export function activate(context: vscode
   const clangdClient = new ClangdLanguageClient('Clang Language Server',
                                                 serverOptions, clientOptions);
   const semanticHighlightingFeature =
-      new semanticHighlighting.SemanticHighlightingFeature();
+      new semanticHighlighting.SemanticHighlightingFeature(clangdClient,
+                                                           context);
   context.subscriptions.push(
       vscode.Disposable.from(semanticHighlightingFeature));
   clangdClient.registerFeature(semanticHighlightingFeature);
@@ -144,14 +145,9 @@ export function activate(context: vscode
       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

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts?rev=371036&r1=371035&r2=371036&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts Thu Sep  5 02:14:04 2019
@@ -44,7 +44,7 @@ export interface SemanticHighlightingLin
 
 // 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,19 @@ export class SemanticHighlightingFeature
   highlighter: Highlighter;
   // Any disposables that should be cleaned up when clangd crashes.
   private subscriptions: vscode.Disposable[] = [];
+  constructor(client: vscodelc.BaseLanguageClient,
+              context: vscode.ExtensionContext) {
+    context.subscriptions.push(client.onDidChangeState(({newState}) => {
+      if (newState == vscodelc.State.Running) {
+        // Register handler for semantic highlighting notification.
+        client.onNotification(NotificationType,
+                              this.handleNotification.bind(this));
+      } else if (newState == vscodelc.State.Stopped) {
+        // Dispose resources when clangd crashes.
+        this.dispose();
+      }
+    }));
+  }
   fillClientCapabilities(capabilities: vscodelc.ClientCapabilities) {
     // Extend the ClientCapabilities type and add semantic highlighting
     // capability to the object.




More information about the cfe-commits mailing list