[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
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@371036 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/clangd/clients/clangd-vscode/src/extension.ts b/clangd/clients/clangd-vscode/src/extension.ts
index fa787f9..4cd7b0e 100644
--- a/clangd/clients/clangd-vscode/src/extension.ts
+++ b/clangd/clients/clangd-vscode/src/extension.ts
@@ -110,7 +110,8 @@
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 @@
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
diff --git a/clangd/clients/clangd-vscode/src/semantic-highlighting.ts b/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
index 27dfb8b..930079b 100644
--- a/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ b/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,19 @@
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.