From 32e4acdadce83a8526da12bf0556c320eea3c834 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Wed, 26 Jul 2017 01:46:21 +0200 Subject: [PATCH] Fix #1072 Avoid completions in block comments Previously completions were suppressed in single line comments only. We now also avoid providing completions within block comments. --- src/goSuggest.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/goSuggest.ts b/src/goSuggest.ts index 56cbbfbd1..2e398ccec 100644 --- a/src/goSuggest.ts +++ b/src/goSuggest.ts @@ -44,6 +44,14 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider { return this.provideCompletionItemsInternal(document, position, token, vscode.workspace.getConfiguration('go')); } + private isInBlockComment(document: vscode.TextDocument, position: vscode.Position): boolean { + let text = document.getText(); + let currentOffset = document.offsetAt(position); + let lastBlockCommentStartIndex = text.lastIndexOf('/*', currentOffset); + let lastBlockCommentEndIndex = text.lastIndexOf('*/', currentOffset); + return lastBlockCommentStartIndex > lastBlockCommentEndIndex; + } + public provideCompletionItemsInternal(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, config: vscode.WorkspaceConfiguration): Thenable { return this.ensureGoCodeConfigured().then(() => { return new Promise((resolve, reject) => { @@ -52,10 +60,16 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider { let lineTillCurrentPosition = lineText.substr(0, position.character); let autocompleteUnimportedPackages = config['autocompleteUnimportedPackages'] === true && !lineText.match(/^(\s)*(import|package)(\s)+/); + // no completions within single line comment if (lineText.match(/^\s*\/\//)) { return resolve([]); } + // no completions within block comment + if (this.isInBlockComment(document, position)) { + return resolve([]); + } + let inString = isPositionInString(document, position); if (!inString && lineTillCurrentPosition.endsWith('\"')) { return resolve([]);