-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: feature: code action to generate a stub function from a "no function f" type error #69692
Comments
gopls already has a related feature, stubmethods, that is admittedly a little hard to find. (The same is unfortunately also true of its documentation.) This seems like a reasonable feature request for a new type-error analyzer. |
Nice, I'm looking at this feature, are there similar PRs that I can borrow from? |
Search the codebase for
You should follow this structure. The stubmethods code may have nuggets you can steal/share. |
Hmm, I notice the TODO comment not to do things this way. It might be simpler to avoid the analyzer altogether and just follow the code action plugin approach used by refactorRewriteRemoveUnusedParam, which also inspects |
@xzbdmw you may want to take a look at https://go.dev/cl/617035, which reorganizes |
Is it possible to get the error node's type by type inference, so the generated function can have correct return value? use If the info can not be retrieved easily, we need to guess the type by looking up parent node, eg. variable assignment, parameter assignment, return statement etc. |
The type checker records the type of each expression, but not the type of each "hole" that is filled by that expression. This would be very useful information for a wide range of analyses, but unfortunately it is not available. Gopl's completion engine goes to great lengths to infer it, but not in a way that is easily reused. |
Change https://go.dev/cl/617619 mentions this issue: |
Change https://go.dev/cl/621841 mentions this issue: |
… position This CL adds the logic to insert generated method stubs immediately after the enclosing method declaration when the receiver types match. I often find myself move the generated code to the position after current method immediately, and this added logic is more consistent with undeclared.go's generate missing function quickfix. Related CL 617619 Updates golang/go#69692 Change-Id: Ia07422a0da7ee38ce648508dbb3e392f3dc8c93d GitHub-Last-Rev: 0abde90 GitHub-Pull-Request: #537 Reviewed-on: https://go-review.googlesource.com/c/tools/+/621841 Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
@adonovan do you mind seeing a similar quick fix, but to declare a struct field? I couldn’t find it in the actual implementation. |
gopls version
golang.org/x/tools/gopls (devel)
golang.org/x/tools/gopls@(devel)
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:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/[email protected] h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/[email protected] h1:nU8/tAV/21mkPrCjACUeSibjhynTovgRMXc32+Y1Aec=
golang.org/x/[email protected] h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
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:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.22.4
go env
What did you do?
The
|
stands for cursor positionI expect a code action that auto generate the missing methods, result in
What did you see happen?
There are no similar action
What did you expect to see?
provide the action
Here is similar action in rust-analyzer:
Editor and settings
No response
Logs
No response
The text was updated successfully, but these errors were encountered: