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

Commit

Permalink
Update logic that determines in string position (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a authored Oct 31, 2016
1 parent b143a0d commit 5df5cd2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/goSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
return resolve([]);
}

let inString = false;
if ((lineText.substring(0, position.character).match(/\"/g) || []).length % 2 === 1) {
inString = true;
// Count the number of double quotes in the line till current position. Ignore escaped double quotes
let doubleQuotesCnt = (lineTillCurrentPosition.match(/[^\\]\"/g) || []).length;
doubleQuotesCnt += lineTillCurrentPosition.startsWith('\"') ? 1 : 0;
let inString = (doubleQuotesCnt % 2 === 1);

if (!inString && lineTillCurrentPosition.endsWith('\"')) {
return resolve([]);
}

// get current word
Expand All @@ -82,7 +86,7 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
let inputText = document.getText();

return this.runGoCode(filename, inputText, offset, inString, position, lineText).then(suggestions => {
if (!autocompleteUnimportedPackages) {
if (!autocompleteUnimportedPackages || inString) {
return resolve(suggestions);
}

Expand Down

0 comments on commit 5df5cd2

Please sign in to comment.