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

Avoid duplicate function parameter body on function suggest snippets #1696

Merged
merged 3 commits into from
Jun 3, 2018
Merged
Changes from 2 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: 9 additions & 1 deletion src/goSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,15 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
paramSnippets.push('${' + (i + 1) + ':' + param + '}');
}
}
item.insertText = new vscode.SnippetString(suggest.name + '(' + paramSnippets.join(', ') + ')');
let newSnippetString = null;
// Avoid adding snippet for function suggest when cursor is followed by ()
// i.e: met() -> method()()
if (lineText.substr(position.character, 2) === '()') {
newSnippetString = new vscode.SnippetString(suggest.name);
Copy link
Contributor

Choose a reason for hiding this comment

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

@lggomez

We don't need to create a vscode.SnippetString in this case.
When item.insertText is not set, then item.label is used by the auto-completion feature.
See https://github.com/Microsoft/vscode/blob/1.23.0/src/vs/vscode.d.ts#L3047-L3052

} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not skip setting the item.insertText altogether if the cursor is followed by ()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because keeping the text insert will still autocomplete the function name sans the param snippets

newSnippetString = new vscode.SnippetString(suggest.name + '(' + paramSnippets.join(', ') + ')');
}
item.insertText = newSnippetString;
}
if (config['useCodeSnippetsOnFunctionSuggest'] && suggest.class === 'type' && suggest.type.startsWith('func(')) {
let { params, returnType } = getParametersAndReturnType(suggest.type.substring(4));
Expand Down