From 1f621cc7f5d722c2ebdd61f5aeeaea2973a26da5 Mon Sep 17 00:00:00 2001 From: Sardorbek <15870134+oneslash@users.noreply.github.com> Date: Mon, 4 Mar 2019 03:27:15 +0100 Subject: [PATCH] fix: #2240 - gocode autocompletion not working when using // in Sprintf (#2316) --- src/goSuggest.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/goSuggest.ts b/src/goSuggest.ts index 80e761ad1..d06cd82a6 100644 --- a/src/goSuggest.ts +++ b/src/goSuggest.ts @@ -126,13 +126,20 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider, let suggestionItem: vscode.CompletionItem; if (memberType && memberType.length === 4) { suggestionItem = new vscode.CompletionItem(memberType[3], vscodeKindFromGoCodeClass(memberType[1], '')); - } - return resolve(suggestionItem ? [suggestionItem] : []); } + return resolve(suggestionItem ? [suggestionItem] : []); + } + // prevent completion when typing in a line comment that doesnt start from the beginning of the line const commentIndex = lineText.indexOf('//'); + if (commentIndex >= 0 && position.character > commentIndex) { - return resolve([]); + const commentPosition = new vscode.Position(position.line, commentIndex); + const isCommentInString = isPositionInString(document, commentPosition); + + if (!isCommentInString) { + return resolve([]); + } } let inString = isPositionInString(document, position);