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/[email protected]+dirty
github.com/BurntSushi/[email protected] h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/[email protected] h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
golang.org/x/[email protected] h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/[email protected] h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/[email protected] h1:Wm3cG5X6sZ0RSVRc/H1/sciC4AT6HAKgLCSH2lbpR/c=
golang.org/x/[email protected] h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/[email protected] => ../
golang.org/x/[email protected] h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
honnef.co/go/[email protected] h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
mvdan.cc/[email protected] h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=
mvdan.cc/xurls/[email protected] 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: