Skip to content

Commit 67e3a26

Browse files
committed
src/language/goLanguageServer: fix signature help trigger injection
Triggering signature help after completion was implemented by injecting the followup command for each Method/Function type completion item from the middleware. Unfortunately, we used a wrong enum (lsp proto CompletionItemKind instead of vscode API's CompletionItemKind). LSP enums are 0-based, while vscode API's enums are 1-based. As a result, we failed to correctly inject trigger parameter hint action for Method type completion items. For #2515 Change-Id: Ib75dd8f14f421aad9b2a2682a8e7e0621b2effd9 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/446816 TryBot-Result: kokoro <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Peter Weinberger <[email protected]>
1 parent 318539d commit 67e3a26

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/language/goLanguageServer.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import vscode = require('vscode');
1717
import {
1818
CancellationToken,
1919
CloseAction,
20-
CompletionItemKind,
2120
ConfigurationParams,
2221
ConfigurationRequest,
2322
ErrorAction,
@@ -51,7 +50,7 @@ import {
5150
} from '../util';
5251
import { getToolFromToolPath } from '../utils/pathUtils';
5352
import WebRequest = require('web-request');
54-
import { FoldingContext } from 'vscode';
53+
import { CompletionItemKind, FoldingContext } from 'vscode';
5554
import { ProvideFoldingRangeSignature } from 'vscode-languageclient/lib/common/foldingRange';
5655
import { daysBetween, getStateConfig, maybePromptForGoplsSurvey, timeDay, timeMinute } from '../goSurvey';
5756
import { maybePromptForDeveloperSurvey } from '../goDeveloperSurvey';
@@ -712,7 +711,7 @@ async function adjustGoplsWorkspaceConfiguration(
712711
if (!extensionInfo.isPreview) {
713712
return workspaceConfig;
714713
}
715-
if (!workspaceConfig['allExperiments']) {
714+
if (workspaceConfig && !workspaceConfig['allExperiments']) {
716715
workspaceConfig['allExperiments'] = true;
717716
}
718717
return workspaceConfig;

test/gopls/extension.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,12 @@ suite('Go Extension Tests With Gopls', function () {
205205

206206
test('Completion middleware', async () => {
207207
const { uri } = await env.openDoc(testdataDir, 'gogetdocTestData', 'test.go');
208-
const testCases: [string, vscode.Position, string][] = [['fmt.P<>', new vscode.Position(19, 6), 'Print']];
209-
for (const [name, position, wantFilterText] of testCases) {
208+
const testCases: [string, vscode.Position, string, vscode.CompletionItemKind][] = [
209+
['fmt.P<>', new vscode.Position(19, 6), 'Print', vscode.CompletionItemKind.Function],
210+
['xyz.H<>', new vscode.Position(41, 13), 'Hello', vscode.CompletionItemKind.Method]
211+
];
212+
213+
for (const [name, position, wantFilterText, wantItemKind] of testCases) {
210214
let list: vscode.CompletionList<vscode.CompletionItem> | undefined;
211215
// Query completion items. We expect the hard coded filter text hack
212216
// has been applied and gopls returns an incomplete list by default
@@ -237,6 +241,7 @@ suite('Go Extension Tests With Gopls', function () {
237241
// Alternative is to directly query the language client, but that will
238242
// prevent us from detecting problems caused by issues between the language
239243
// client library and the vscode.
244+
let itemKindFound = false;
240245
for (const item of list.items) {
241246
if (item.kind === vscode.CompletionItemKind.Snippet) {
242247
continue;
@@ -248,6 +253,9 @@ suite('Go Extension Tests With Gopls', function () {
248253
`(got ${item.filterText ?? item.label}, want ${wantFilterText})\n` +
249254
`${JSON.stringify(item, null, 2)}`
250255
);
256+
if (item.kind === wantItemKind) {
257+
itemKindFound = true;
258+
}
251259
if (
252260
item.kind === vscode.CompletionItemKind.Method ||
253261
item.kind === vscode.CompletionItemKind.Function
@@ -258,6 +266,7 @@ suite('Go Extension Tests With Gopls', function () {
258266
);
259267
}
260268
}
269+
assert(itemKindFound, `failed to find expected item kind ${wantItemKind}: got ${JSON.stringify(list)}`);
261270
}
262271
});
263272

0 commit comments

Comments
 (0)