-
Notifications
You must be signed in to change notification settings - Fork 2.3k
internal/lsp/source: Add useAutoBraces option. #272
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
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
This PR (HEAD: 706fb82) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/tools/+/287172 to see it. Tip: You can toggle comments from me using the |
Message from Go Bot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be Please don’t reply on this GitHub thread. Visit golang.org/cl/287172. |
Message from Rebecca Stambler: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/287172. |
Message from Rebecca Stambler: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/287172. |
Fixes: golang/go#43903
This PR adds a new option
useAutoBraces
to gopls which, if set false, will make it so gopls will not add a () to the end of an auto-completion for a function. The default value is true, to keep the current behavior, but actually I think you could make a pretty strong case for setting the default to false.The problem here is that, in VSCode, when you auto-complete a function name in any programming language other than go (at least any that are maintained by Microsoft), these brackets are not inserted. The completion behavior of gopls is unique, which means if your day job is writing in some other language and you only occasionally write in go, the editor is always not behaving the way you expect it to, and you have to fight the muscle memory you've developed from other languages.
For example, let's open up VSCode and write "Hello World" in Python. You type:
(You can optionally not type the closing bracket if you're using the default settings, as VSCode will insert it for you when you type the open bracket. If you do type it, the close bracket will "overtype" the existing one, so it works either way.) This results in:
It's the same in any language:
Etc... You'll note, aside from the fact that the function is named something different in each case, that we're typing basically exactly the same thing and getting the same result. The Visual Studio family of products have a very consistent "interaction model" here, allowing you to switch from one language to another without the behavior of Visual Studio changing.
But, in go:
We get:
Note the double brackets. If we tried to pass two parameters, this would be a syntax error. It's even worse if you have the "editor.autoClosingBrackets" set to "never", then you get
fmt.Println(("Hello World!")
- only double brackets at the start.gopls has this cool feature where, when it returns a suggestion for "fmt.Println", it actually returns a snippet which sends back "fmt.Println()", and places the cursor in between the brackets. This is very clever, and I'm sure lots of people like this, and if you write predominantly go all day I'm sure this works great. But as mentioned above, if you spend most of your time in some other language, and only write go occasionally, then your muscle memory is basically hard coded to type "<tab>(" every time you want to call a function, and thus in go, you find yourself constantly having to backspace away extra brackets, and slowly losing your mind. :P It's also worth noting that when this "auto bracket" feature was requested back when Microsoft was still maintaining the go plugin, they turned it down for exactly this reason.
So, this PR makes this behavior controlled by an option, so at least you can turn it off if it's driving you crazy. :)