Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
goLanguageServer: set completion follow up command from middleware (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hyangah authored Mar 20, 2020
1 parent 00c318b commit d53b1b3
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/goLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import semver = require('semver');
import util = require('util');
import vscode = require('vscode');
import {
Command,
FormattingOptions,
HandleDiagnosticsSignature,
LanguageClient,
Expand Down Expand Up @@ -143,6 +144,55 @@ export async function registerLanguageFeatures(ctx: vscode.ExtensionContext) {
return null;
}
return next(document, token);
},
provideCompletionItem: (
document: vscode.TextDocument,
position: vscode.Position,
context: vscode.CompletionContext,
token: vscode.CancellationToken,
next: ProvideCompletionItemsSignature
) => {
// TODO(hyangah): when v1.42+ api is available, we can simplify
// language-specific configuration lookup using the new
// ConfigurationScope.
// const paramHintsEnabled = vscode.workspace.getConfiguration(
// 'editor.parameterHints',
// { languageId: 'go', uri: document.uri });

const editorParamHintsEnabled = vscode.workspace.getConfiguration(
'editor.parameterHints', document.uri)['enabled'];
const goParamHintsEnabled = vscode.workspace.getConfiguration(
'[go]', document.uri)['editor.parameterHints.enabled'];

let paramHintsEnabled: boolean = false;
if (typeof goParamHintsEnabled === 'undefined') {
paramHintsEnabled = editorParamHintsEnabled;
} else {
paramHintsEnabled = goParamHintsEnabled;
}
let cmd: Command;
if (paramHintsEnabled) {
cmd = { title: 'triggerParameterHints', command: 'editor.action.triggerParameterHints' };
}

function configureCommands(
r: vscode.CompletionItem[] | vscode.CompletionList | null | undefined):
vscode.CompletionItem[] | vscode.CompletionList | null | undefined {
if (r) {
(Array.isArray(r) ? r : r.items).forEach((i: vscode.CompletionItem) => {
i.command = cmd;
});
}
return r;
}
const ret = next(document, position, context, token);

const isThenable = <T>(obj: vscode.ProviderResult<T>): obj is Thenable<T> => obj && (<any>obj)['then'];
if (isThenable<vscode.CompletionItem[] | vscode.CompletionList | null | undefined>(ret)) {
return ret.then(configureCommands);
}
return configureCommands(ret);

}
}
}
Expand Down

0 comments on commit d53b1b3

Please sign in to comment.