Skip to content

Commit

Permalink
[TypeHierarchy] Properly handle standard protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
kadircet committed Oct 11, 2022
1 parent 9b82222 commit 52ef0f6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/type-hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ class TypeHierarchyTreeItem extends vscode.TreeItem {
class TypeHierarchyFeature implements vscodelc.StaticFeature {
private serverSupportsTypeHierarchy = false;
private state!: vscodelc.State;
private context: ClangdContext;

constructor(context: ClangdContext) {
this.context = context;
new TypeHierarchyProvider(context);
context.subscriptions.push(context.client.onDidChangeState(stateChange => {
this.state = stateChange.newState;
Expand All @@ -116,10 +118,21 @@ class TypeHierarchyFeature implements vscodelc.StaticFeature {
initialize(capabilities: vscodelc.ServerCapabilities,
documentSelector: vscodelc.DocumentSelector|undefined) {
const serverCapabilities: vscodelc.ServerCapabilities&
{typeHierarchyProvider?: any} = capabilities;
if (serverCapabilities.typeHierarchyProvider) {
{standardTypeHierarchyProvider?: any} = capabilities;
// Unfortunately clangd used the same capability name for its pre-standard
// protocol as the standard ended up using. We need to prevent
// vscode-languageclient from trying to query clangd versions that speak the
// incompatible protocol.
if (serverCapabilities.typeHierarchyProvider &&
!serverCapabilities.standardTypeHierarchyProvider) {
// Disable mis-guided support for standard type-hierarchy feature.
this.context.client.getFeature('textDocument/prepareTypeHierarchy')
.dispose();
this.serverSupportsTypeHierarchy = true;
this.recomputeEnableTypeHierarchy();
} else {
// Either clangd has support for the standard protocol, or no
// implementation at all. In either case, don't turn on the extension.
}
}
getState(): vscodelc.FeatureState { return {kind: 'static'}; }
Expand Down

0 comments on commit 52ef0f6

Please sign in to comment.