golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.79k stars 729 forks source link

Stop auto insertion of square brackets when using a generic function #3176

Closed drunkenplatypus closed 4 months ago

drunkenplatypus commented 4 months ago

I find it annoying when you use IntelliSense to autocomplete a generic function and are left with e.g. slices.Contains[]() with your cursor between the square brackets.

In a lot of cases providing an explicit type isn't required, and it can be inferred from the provided argument e.g. slices.Contains([]string{}, "foo")

It would be nice if this behaviour was configurable so that generic functions behaved like any other function.

hyangah commented 4 months ago

What version of gopls are you using? Can you give a try to v0.15.0 prerelease? When the types can be inferred, v0.15.0-pre.3 omits type param. Screenshot 2024-02-16 at 11 52 00 AM

findleyr commented 4 months ago

Indeed: gopls@v0.15.0 indends to fix this:

go install golang.org/x/tools/gopls@v0.15.0-pre.3
drunkenplatypus commented 4 months ago

Yeah installing that version of gopls fixed it for me, thanks both!