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

goLanguageServer: set completion follow up command from middleware #3084

Merged
merged 2 commits into from
Mar 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
ramya-rao-a marked this conversation as resolved.
Show resolved Hide resolved
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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we expecting ret to be a thenable resolving to null or undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vscode.ProviderResult (the return type of next) allows null or undefined.

return ret.then(configureCommands);
}
return configureCommands(ret);

}
}
}
Expand Down