Skip to content
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

jwalton opened this issue Jan 25, 2021 · 8 comments · May be fixed by golang/tools#272

x/tools/gopls: option for not automatically inserting brackets #43903

jwalton opened this issue Jan 25, 2021 · 8 comments · May be fixed by golang/tools#272


Copy link

@jwalton jwalton commented Jan 25, 2021

What version of Go are you using (go version)?

$ go version
go version go1.15.5 darwin/amd64

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOENV="/Users/jwalton/Library/Application Support/go/env"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/42/y3h31nrx5c98b7sq_vqskskw0000gn/T/go-build712473597=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

In VSCode, if I type fmt.Prin<tab>, then VSCode replaces what I typed with fmt.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 in console.log, and I have to type the "(". Since I spend 90% of my time in Typescript, I'm kinda hard wired to typing console.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 type fmt.Prin<tab>("test"), then you might expect this to "work out" because I ought to get fmt.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 get fmt.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.


What did you see instead?

There is no such option. :(


@gopherbot gopherbot added this to the Unreleased milestone Jan 25, 2021
@stamblerre stamblerre changed the title x/tools/gopls: Option for not automatically inserting brackets x/tools/gopls: option for not automatically inserting brackets Jan 25, 2021
Copy link

@pjweinb pjweinb commented Jan 25, 2021

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.

Copy link

@jwalton jwalton commented Jan 25, 2021

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 .py file in VSCode and type pri<tab> it completes to print, and not print(). If I open up a C# project in Visual Studio (not code), and type in this.Equ<tab>, it replaces it with this.Equals, and not this.Equals(). I'm sure it's fine if you only write Golang code, but having one language behave differently than tall the others is... not fun.

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 ()).

Copy link

@muirdm muirdm commented Jan 26, 2021

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.

Copy link

@jwalton jwalton commented Jan 26, 2021

@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 editor.suggest.showSnippets doesn't seem to help (but I assume this isn't what you mean anyways), nor does disabling snippets for go via:

    "[go]": {
        "editor.snippetSuggestions": "none"
Copy link

@muirdm muirdm commented Jan 26, 2021

It is a client capability. The LSP client sets the textDocument.completion.snippetSupport capability to false (see

Copy link

@jwalton jwalton commented Jan 27, 2021

Aha. If I comment out these lines in gopls, it does indeed fix this. That does seem like kind of a sledgehammer though.

Copy link

@jwalton jwalton commented Feb 1, 2021

@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.

Copy link

@pjweinb pjweinb commented Feb 1, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants