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

Fixes #573 Update logic that determines in string position #586

Merged
merged 1 commit into from
Oct 31, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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