x/tools/gopls: reverse type inference for completions in generic function call params #69754
Labels
FeatureRequest
gopls/completion
Issues related to auto-completion in gopls.
gopls
Issues related to the Go language server, gopls.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
gopls version
golang.org/x/tools/gopls v0.0.0-20240919171440-cd349f34d533+dirty
golang.org/x/tools/gopls@v0.0.0-20240919171440-cd349f34d533+dirty
github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
golang.org/x/mod@v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/sync@v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/telemetry@v0.0.0-20240829154258-f29ab539cc98 h1:Wm3cG5X6sZ0RSVRc/H1/sciC4AT6HAKgLCSH2lbpR/c=
golang.org/x/text@v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/tools@v0.21.1-0.20240508182429-e35e4ccd0d2d => ../
golang.org/x/vuln@v1.0.4 h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
honnef.co/go/tools@v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
mvdan.cc/gofumpt@v0.7.0 h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=
mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: devel go1.24-097b7162ad Fri Sep 20 20:19:15 2024 +0000
go env
What did you do?
This is a feature request.
When writing a generic function that returns a parameterized type in an assignment, gopls makes no "reverse type inferences" for completions in the function parameters. With reverse type inference, completions could exist for type parameters, and automatic conversion completions for interface types.
I have a video that demonstrates a patched implementation with this working
completions.mov
I measured that when using libraries that make heavy use of generics, there is a roughly 5x productivity boost after this was patched.
What did you see happen?
No special completions, just lexical
What did you expect to see?
Case 1.
I would expect completions of with the following options
ia
ta
TypeA{}
Additionally,
ta
andTypeA{}
should have a conversion toInterfaceA(ta)
orInterfaceA(TypeA{})
when they are selected.Case 2.
This should complete to the type name
InterfaceA
Editor and settings
No response
Logs
No response
The text was updated successfully, but these errors were encountered: