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

#2063 only suggest exported member name at start of comment #2070

Merged
merged 3 commits into from
Jan 20, 2019
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
10 changes: 5 additions & 5 deletions src/goSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ExtendedCompletionItem extends vscode.CompletionItem {
fileName: string;
}

const lineCommentRegex = /^\s*\/\/\s+/;
const lineCommentFirstWordRegex = /^\s*\/\/\s+[\S]*$/;
const exportedMemberRegex = /(const|func|type|var)(\s+\(.*\))?\s+([A-Z]\w*)/;
const gocodeNoSupportForgbMsgKey = 'dontshowNoSupportForgb';

Expand Down Expand Up @@ -133,15 +133,15 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
let autocompleteUnimportedPackages = config['autocompleteUnimportedPackages'] === true && !lineText.match(/^(\s)*(import|package)(\s)+/);

// triggering completions in comments on exported members
if (lineCommentRegex.test(lineTillCurrentPosition) && position.line + 1 < document.lineCount) {
if (lineCommentFirstWordRegex.test(lineTillCurrentPosition) && position.line + 1 < document.lineCount) {
let nextLine = document.lineAt(position.line + 1).text.trim();
let memberType = nextLine.match(exportedMemberRegex);
let suggestionItem: vscode.CompletionItem;
if (memberType && memberType.length === 4) {
suggestionItem = new vscode.CompletionItem(memberType[3], vscodeKindFromGoCodeClass(memberType[1], ''));
suggestionItem = new vscode.CompletionItem(memberType[3], vscodeKindFromGoCodeClass(memberType[1], ''));
}
return resolve(suggestionItem ? [suggestionItem] : []);
Copy link
Contributor

@ramya-rao-a ramya-rao-a Nov 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to move this return statement? With this change, when typing any text in the comments, we would end up calling gocode instead of exiting early

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can you update the existing test case to reflect the bug fix? See https://github.com/Microsoft/vscode-go/blob/0.7.0/test/go.test.ts#L1014

}
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) {
Expand Down