-
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: "replace all occurrences" variants of refactor.{inline,extract}.variable #70085
Comments
Change https://go.dev/cl/623637 mentions this issue: |
Hmm, how could I know two expression is identical regardless their tok.Pos value? Am I supposed to write a util function similar to types.Identical()? |
Change https://go.dev/cl/624035 mentions this issue: |
@adonovan Hey Alan, may you take a look? The logic is relatively simple :) |
Sorry for the delay and thanks for the contribution, but I am overwhelmed with reviews at the moment and am also out of office at a Go conference. I will attend to this next week. |
Thanks! No rush—enjoy the conference! |
Original title: codeaction: replace every use-case of a variable with its defined expression, extract every identical expression within function to a new variable
gopls version
Build info
golang.org/x/tools/gopls (devel)
golang.org/x/tools/gopls@(devel)
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-20240927184629-19675431963b h1:PfPrmVDHfPgLVpiYnf2R1uL8SCXBjkqT51+f/fQHR6Q=
golang.org/x/text@v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
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: go1.23.2
go env
What did you do?
iShot_2024-10-29_11.52.53.mp4
the first half part is
:Rafactor inline_var
, and second part is:Rafactor extract_var new_var
, it is from a nvim plugin refactoring.nvim using treesitter under the hood, I use this two quite frequently to eliminate unnecessary variable as well as introduce new variable for some repeated expression, the problem is it fails (or not accurate) in complex situations, so I wish gopls would support this directly.What did you see happen?
Currently gopls supports extract a single expression to a new variable, I'd say extract every repeated expression under selection would be more useful, since the latter contains the former.
What did you expect to see?
see above
Editor and settings
No response
Logs
No response
The text was updated successfully, but these errors were encountered: