Skip to content

Commit

Permalink
Fix inlay-hint not shown issue (clangd#341)
Browse files Browse the repository at this point in the history
* Fix inlay-hint not shown issue when using a standard-inlay-hint-supported clangd

- Fixes #1164;
- Also fixes the `clangd.inlayHints.toggle command not found` issue;
  • Loading branch information
hokein authored Jul 11, 2022
1 parent 5aa93f9 commit eb61c51
Show file tree
Hide file tree
Showing 8 changed files with 1,395 additions and 1,121 deletions.
2,483 changes: 1,373 additions & 1,110 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"dependencies": {
"@clangd/install": "0.1.4",
"abort-controller": "^3.0.0",
"vscode-languageclient": "7.1.0-next.1"
"vscode-languageclient": "8.0.1"
},
"devDependencies": {
"@types/glob": "^7.1.1",
Expand All @@ -60,7 +60,7 @@
"glob": "^7.1.4",
"mocha": "^9.2.0",
"ovsx": "^0.3.0",
"typescript": "^3.8.3",
"typescript": "^4.5.5",
"vsce": "^2.7.0",
"vscode-test": "^1.3.0"
},
Expand Down Expand Up @@ -243,7 +243,8 @@
{
"command": "clangd.inlayHints.toggle",
"category": "clangd",
"title": "Toggle inlay hints"
"title": "Toggle inlay hints",
"enablement": "clangd.inlayHints.supported"
}
],
"keybindings": [
Expand Down
1 change: 1 addition & 0 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class ASTFeature implements vscodelc.StaticFeature {
vscode.commands.executeCommand('setContext', 'clangd.ast.supported',
'astProvider' in capabilities);
}
getState(): vscodelc.FeatureState { return {kind: 'static'}; }
dispose() {}
}

Expand Down
4 changes: 3 additions & 1 deletion src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class EnableEditsNearCursorFeature implements vscodelc.StaticFeature {
capabilities.textDocument?.completion;
extendedCompletionCapabilities.editsNearCursor = true;
}
getState(): vscodelc.FeatureState { return {kind: 'static'}; }
dispose() {}
}

Expand Down Expand Up @@ -156,7 +157,7 @@ export class ClangdContext implements vscode.Disposable {
memoryUsage.activate(this);
ast.activate(this);
openConfig.activate(this);
this.subscriptions.push(this.client.start());
await this.client.start();
console.log('Clang Language Server is now active!');
fileStatus.activate(this);
switchSourceHeader.activate(this);
Expand All @@ -170,6 +171,7 @@ export class ClangdContext implements vscode.Disposable {

dispose() {
this.subscriptions.forEach((d) => { d.dispose(); });
this.client.stop();
this.subscriptions = []
}
}
1 change: 1 addition & 0 deletions src/config-file-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ConfigFileWatcherFeature implements vscodelc.StaticFeature {
return;
this.context.subscriptions.push(new ConfigFileWatcher(this.context));
}
getState(): vscodelc.FeatureState { return {kind: 'static'}; }
dispose() {}
}

Expand Down
16 changes: 10 additions & 6 deletions src/inlay-hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ class InlayHintsFeature implements vscodelc.StaticFeature {
const serverCapabilities: vscodelc.ServerCapabilities&
{clangdInlayHintsProvider?: boolean, inlayHintProvider?: any} =
capabilities;
// If the clangd server supports LSP 3.17 inlay hints, these are handled by
// the vscode-languageclient library - don't send custom requests too!
if (!serverCapabilities.clangdInlayHintsProvider ||
serverCapabilities.inlayHintProvider)
return;
vscode.commands.executeCommand(
'setContext', 'clangd.inlayHints.supported',
serverCapabilities.clangdInlayHintsProvider ||
serverCapabilities.inlayHintProvider);
if (!this.commandRegistered) {
// The command provides a quick way to toggle inlay hints
// (key-bindable).
Expand All @@ -74,10 +73,15 @@ class InlayHintsFeature implements vscodelc.StaticFeature {
enabledSetting, !current, vscode.ConfigurationTarget.Global);
}));
}
// If the clangd server supports LSP 3.17 inlay hints, these are handled by
// the vscode-languageclient library - don't send custom requests too!
if (!serverCapabilities.clangdInlayHintsProvider ||
serverCapabilities.inlayHintProvider)
return;
this.context.subscriptions.push(vscode.languages.registerInlayHintsProvider(
clangdDocumentSelector, new Provider(this.context)));
}

getState(): vscodelc.FeatureState { return {kind: 'static'}; }
dispose() {}
}

Expand Down
1 change: 1 addition & 0 deletions src/memory-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class MemoryUsageFeature implements vscodelc.StaticFeature {
vscode.commands.executeCommand('setContext', 'clangd.memoryUsage.supported',
'memoryUsageProvider' in capabilities);
}
getState(): vscodelc.FeatureState { return {kind: 'static'}; }
dispose() {}
}

Expand Down
3 changes: 2 additions & 1 deletion src/type-hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ class TypeHierarchyFeature implements vscodelc.StaticFeature {
initialize(capabilities: vscodelc.ServerCapabilities,
documentSelector: vscodelc.DocumentSelector|undefined) {
const serverCapabilities: vscodelc.ServerCapabilities&
{typeHierarchyProvider?: boolean} = capabilities;
{typeHierarchyProvider?: any} = capabilities;
if (serverCapabilities.typeHierarchyProvider) {
this.serverSupportsTypeHierarchy = true;
this.recomputeEnableTypeHierarchy();
}
}
getState(): vscodelc.FeatureState { return {kind: 'static'}; }
dispose() {}

private recomputeEnableTypeHierarchy() {
Expand Down

0 comments on commit eb61c51

Please sign in to comment.