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

Commit d53b1b3

Browse files
authored
goLanguageServer: set completion follow up command from middleware (#3084)
1 parent 00c318b commit d53b1b3

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/goLanguageServer.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import semver = require('semver');
1212
import util = require('util');
1313
import vscode = require('vscode');
1414
import {
15+
Command,
1516
FormattingOptions,
1617
HandleDiagnosticsSignature,
1718
LanguageClient,
@@ -143,6 +144,55 @@ export async function registerLanguageFeatures(ctx: vscode.ExtensionContext) {
143144
return null;
144145
}
145146
return next(document, token);
147+
},
148+
provideCompletionItem: (
149+
document: vscode.TextDocument,
150+
position: vscode.Position,
151+
context: vscode.CompletionContext,
152+
token: vscode.CancellationToken,
153+
next: ProvideCompletionItemsSignature
154+
) => {
155+
// TODO(hyangah): when v1.42+ api is available, we can simplify
156+
// language-specific configuration lookup using the new
157+
// ConfigurationScope.
158+
// const paramHintsEnabled = vscode.workspace.getConfiguration(
159+
// 'editor.parameterHints',
160+
// { languageId: 'go', uri: document.uri });
161+
162+
const editorParamHintsEnabled = vscode.workspace.getConfiguration(
163+
'editor.parameterHints', document.uri)['enabled'];
164+
const goParamHintsEnabled = vscode.workspace.getConfiguration(
165+
'[go]', document.uri)['editor.parameterHints.enabled'];
166+
167+
let paramHintsEnabled: boolean = false;
168+
if (typeof goParamHintsEnabled === 'undefined') {
169+
paramHintsEnabled = editorParamHintsEnabled;
170+
} else {
171+
paramHintsEnabled = goParamHintsEnabled;
172+
}
173+
let cmd: Command;
174+
if (paramHintsEnabled) {
175+
cmd = { title: 'triggerParameterHints', command: 'editor.action.triggerParameterHints' };
176+
}
177+
178+
function configureCommands(
179+
r: vscode.CompletionItem[] | vscode.CompletionList | null | undefined):
180+
vscode.CompletionItem[] | vscode.CompletionList | null | undefined {
181+
if (r) {
182+
(Array.isArray(r) ? r : r.items).forEach((i: vscode.CompletionItem) => {
183+
i.command = cmd;
184+
});
185+
}
186+
return r;
187+
}
188+
const ret = next(document, position, context, token);
189+
190+
const isThenable = <T>(obj: vscode.ProviderResult<T>): obj is Thenable<T> => obj && (<any>obj)['then'];
191+
if (isThenable<vscode.CompletionItem[] | vscode.CompletionList | null | undefined>(ret)) {
192+
return ret.then(configureCommands);
193+
}
194+
return configureCommands(ret);
195+
146196
}
147197
}
148198
}

0 commit comments

Comments
 (0)