-
Notifications
You must be signed in to change notification settings - Fork 645
Avoid duplicate function parameter body on function suggest snippets #1696
Conversation
Avoid adding snippet for function suggest when cursor is followed by (). Fixes microsoft#1655
src/goSuggest.ts
Outdated
let newSnippetString = null; | ||
// Avoid adding snippet for function suggest when cursor is followed by () | ||
// i.e: met() -> method()() | ||
if ((nextSymbolIndex < lineText.length) && (lineText.charAt(nextSymbolIndex) === '(')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not check lineText.substr(position.character, 2) === '()'
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/goSuggest.ts
Outdated
// i.e: met() -> method()() | ||
if ((nextSymbolIndex < lineText.length) && (lineText.charAt(nextSymbolIndex) === '(')) { | ||
newSnippetString = new vscode.SnippetString(suggest.name); | ||
} else { |
There was a problem hiding this comment.
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 ()
There was a problem hiding this comment.
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
src/goSuggest.ts
Outdated
// 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Avoid adding snippet for function suggest when cursor is followed by (). Fixes #1655