From f87a5fcc6a0056afaa9b0c958a0cfb7a25129c1c Mon Sep 17 00:00:00 2001 From: Luis GG Date: Sat, 4 May 2019 22:43:07 -0300 Subject: [PATCH 1/5] =?UTF-8?q?Don=C2=B4t=20process=20function=20signature?= =?UTF-8?q?s=20on=20comment=20lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 2 +- src/goSignature.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index e96000ae2..f0fcc6c23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "Go", - "version": "0.9.2", + "version": "0.10.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/goSignature.ts b/src/goSignature.ts index 3df17e869..bad7d0f56 100755 --- a/src/goSignature.ts +++ b/src/goSignature.ts @@ -94,6 +94,12 @@ export class GoSignatureHelpProvider implements SignatureHelpProvider { for (let lineNr = position.line; lineNr >= 0 && maxLookupLines >= 0; lineNr-- , maxLookupLines--) { const line = document.lineAt(lineNr); + + // Stop processing if the line is a comment + if (line.text.indexOf('//') > -1) { + return null; + } + // if its current line, get the text until the position given, otherwise get the full line. const [currentLine, characterPosition] = lineNr === position.line ? [line.text.substring(0, position.character), position.character] From c4e886af1a16fd4631fce436dd823a91c4b8015c Mon Sep 17 00:00:00 2001 From: Luis GG Date: Sat, 4 May 2019 22:52:43 -0300 Subject: [PATCH 2/5] Remove false positives on comment line check --- src/goSignature.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/goSignature.ts b/src/goSignature.ts index bad7d0f56..fcf603cd3 100755 --- a/src/goSignature.ts +++ b/src/goSignature.ts @@ -96,7 +96,7 @@ export class GoSignatureHelpProvider implements SignatureHelpProvider { const line = document.lineAt(lineNr); // Stop processing if the line is a comment - if (line.text.indexOf('//') > -1) { + if (line.text.trim().indexOf('//') === 0) { return null; } From 4617bed629ac5afb80fadea3a323e448d9bf8edf Mon Sep 17 00:00:00 2001 From: Luis GG Date: Mon, 6 May 2019 22:46:43 -0300 Subject: [PATCH 3/5] Fix regression on parameter backtracking --- src/goSignature.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/goSignature.ts b/src/goSignature.ts index fcf603cd3..1e6dc29f1 100755 --- a/src/goSignature.ts +++ b/src/goSignature.ts @@ -105,7 +105,7 @@ export class GoSignatureHelpProvider implements SignatureHelpProvider { ? [line.text.substring(0, position.character), position.character] : [line.text, line.text.length - 1]; - for (let char = characterPosition - 1; char >= 0; char--) { + for (let char = characterPosition; char >= 0; char--) { switch (currentLine[char]) { case '(': parenBalance--; From 5b7adc74ff78e5f5f510feac207a765cfd48377b Mon Sep 17 00:00:00 2001 From: Luis GG Date: Mon, 6 May 2019 22:47:15 -0300 Subject: [PATCH 4/5] Improve comment detection --- src/goSignature.ts | 6 +++--- src/goSuggest.ts | 17 +---------------- src/util.ts | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/goSignature.ts b/src/goSignature.ts index 1e6dc29f1..bfb83bc95 100755 --- a/src/goSignature.ts +++ b/src/goSignature.ts @@ -8,7 +8,7 @@ import vscode = require('vscode'); import { SignatureHelpProvider, SignatureHelp, SignatureInformation, ParameterInformation, TextDocument, Position, CancellationToken, WorkspaceConfiguration } from 'vscode'; import { definitionLocation } from './goDeclaration'; -import { getParametersAndReturnType, isPositionInString } from './util'; +import { getParametersAndReturnType, isPositionInString, isPositionInComment } from './util'; export class GoSignatureHelpProvider implements SignatureHelpProvider { @@ -95,8 +95,8 @@ export class GoSignatureHelpProvider implements SignatureHelpProvider { const line = document.lineAt(lineNr); - // Stop processing if the line is a comment - if (line.text.trim().indexOf('//') === 0) { + // Stop processing if we're inside a comment + if (isPositionInComment(document, position)) { return null; } diff --git a/src/goSuggest.ts b/src/goSuggest.ts index a12c08ceb..0594365ca 100644 --- a/src/goSuggest.ts +++ b/src/goSuggest.ts @@ -8,7 +8,7 @@ import path = require('path'); import vscode = require('vscode'); import cp = require('child_process'); -import { getCurrentGoPath, getBinPath, getParametersAndReturnType, parseFilePrelude, isPositionInString, goKeywords, getToolsEnvVars, guessPackageNameFromFile, goBuiltinTypes, byteOffsetAt, runGodoc } from './util'; +import { getCurrentGoPath, getBinPath, getParametersAndReturnType, parseFilePrelude, isPositionInString, goKeywords, getToolsEnvVars, guessPackageNameFromFile, goBuiltinTypes, byteOffsetAt, runGodoc, isPositionInComment } from './util'; import { getCurrentGoWorkspaceFromGOPATH } from './goPath'; import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools'; import { getTextEditForAddImport } from './goImport'; @@ -497,21 +497,6 @@ function getCommentCompletion(document: vscode.TextDocument, position: vscode.Po } } -function isPositionInComment(document: vscode.TextDocument, position: vscode.Position): boolean { - const lineText = document.lineAt(position.line).text; - - // 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) { - const commentPosition = new vscode.Position(position.line, commentIndex); - const isCommentInString = isPositionInString(document, commentPosition); - - return !isCommentInString; - } - return false; -} - function getCurrentWord(document: vscode.TextDocument, position: vscode.Position): string { // get current word const wordAtPosition = document.getWordRangeAtPosition(position); diff --git a/src/util.ts b/src/util.ts index 186a177ca..f088d264d 100644 --- a/src/util.ts +++ b/src/util.ts @@ -954,3 +954,23 @@ export function runGodoc(cwd: string, packagePath: string, receiver: string, sym }); }); } + +/** + * Returns a boolean whether the current position lies within a comment or not + * @param document + * @param position + */ +export function isPositionInComment(document: vscode.TextDocument, position: vscode.Position): boolean { + const lineText = document.lineAt(position.line).text; + + // 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) { + const commentPosition = new vscode.Position(position.line, commentIndex); + const isCommentInString = isPositionInString(document, commentPosition); + + return !isCommentInString; + } + return false; +} From 76543e3cda90d82f202970e95d7493490e358ea8 Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Mon, 6 May 2019 22:57:55 -0700 Subject: [PATCH 5/5] Remove old comment --- src/util.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/util.ts b/src/util.ts index f088d264d..e3a83d9cb 100644 --- a/src/util.ts +++ b/src/util.ts @@ -962,8 +962,6 @@ export function runGodoc(cwd: string, packagePath: string, receiver: string, sym */ export function isPositionInComment(document: vscode.TextDocument, position: vscode.Position): boolean { const lineText = document.lineAt(position.line).text; - - // 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) {