-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/tools/gopls: option for not automatically inserting brackets #43903
Comments
I'm sympathetic when the editor won't do what we want. In my case, the Typescript behavior is infuriating: i almost always want to call the function whose name is being completed. If I want just the function name a simple backspace throws the parens away. On the other hand, if there's a profusion of user settings it's hard to find the one (if it's only one) to change. It would be nice if the editor would just adapt to each user's behavior, but getting there seems very hard. |
I'd suggest using an existing option to key off of instead of adding a new one, but unfortunately there's no "existing" option in VSCode to build off of, because VSCode doesn't anticipate this interaction model at all. The closest is "editor.autoClosingBrackets" which "controls whether the editor should automatically close brackets after the user adds an opening bracket." And this is the problem; the whole VSCode experience is built around the idea that you're going to type that bracket yourself - indeed, the whole Visual Studio tool set. If I open up a While I agree - in most cases - less options is better, in this case the golang plugin is the one actively fighting against the "established norm" in VSCode. So if we want to not have an option, that's fine, but I'd argue in this case we should fix the golang plugin to start behaving like all other languages do, and just not add the ()s. If we're going to keep the auto ()s, then the golang plugin should add an option so those of us long time Visual Studio users who are set in our ways can at least make it behave sensibly (and I'd strongly argue the default for that option should be to not auto-add the |
You can disable the parens by disabling snippets (this will disable all gopls snippets, which may or may not be what you want). I don't know in particular how to configure VSCode to disable gopls snippets. |
@muirdom Could you please elaborate on this workaround? How would you disable snippets? I don't see any options to disable snippets in the gopls settings. Disabling snippets globally in VSCode via "[go]": {
"editor.snippetSuggestions": "none"
}, |
It is a client capability. The LSP client sets the textDocument.completion.snippetSupport capability to false (see https://microsoft.github.io/language-server-protocol/specification#textDocument_completion). |
Aha. If I comment out these lines in gopls, it does indeed fix this. That does seem like kind of a sledgehammer though. |
@pjweinb I've just discovered that typescript has a setting that behaves (more or less) like gopls with |
thank you
…On Mon, Feb 1, 2021 at 12:25 PM Jason Walton ***@***.***> wrote:
@pjweinb <https://github.com/pjweinb> I've just discovered that
typescript has a setting that behaves (more or less) like gopls with
ui.completion.usePlaceholders turned on. If you enable the setting
typescript.suggest.completeFunctionCalls in vscode, then myFun<tab> will
complete to myFunction(x, y, z) with "x" selected ready to type over (and
you can tab to y and z). I don't think there's a setting that will make it
behave exactly like golang, though.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#43903 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJIAIYHV6G2WOCAPEIC6LDS43PW5ANCNFSM4WSGTELA>
.
|
I think this is a dupe of #41813. |
Thanks @muirdm, I agree. Closing this in favor of the earlier issue. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
In VSCode, if I type
fmt.Prin<tab>
, then VSCode replaces what I typed withfmt.Printf()
and places my cursor between the brackets. There seems to be no option to disable auto-adding the brackets.In Typescript, if I type
console.lo<tab>
, VSCode fills inconsole.log
, and I have to type the "(". Since I spend 90% of my time in Typescript, I'm kinda hard wired to typingconsole.lo<tab>(
. In Golang, because I type that extra bracket (and VSCode isn't smart enough to "overtype" the opening bracket) it adds an extra bracket, which I then have to go back and remove. In fact, in golang if I typefmt.Prin<tab>("test")
, then you might expect this to "work out" because I ought to getfmt.Println(("test"))
, and then the code formatter would fix it (assuming I only have one variable at any rate), but if you try it you'll actually getfmt.Println(("test")
because VSCode will "overtype" the closing bracket for you but not the opening bracket, so you end up with a syntax error, even though you typed something perfectly sensible.@hyangah directed me here, and noted that in order to implement this option in VSCode, support would need to be added to gopls.
I would also reference this issue in the old vscode-go repo, where MS explained they didn't auto-add the ()s because "this is not the standard interaction model for VS Code." I understand why some people might like this behavior, but there should at least be an option to turn it off.
What did you expect to see?
There should be an option to disable auto-brackets.
fmt.Println
What did you see instead?
There is no such option. :(
fmt.Println()
The text was updated successfully, but these errors were encountered: