golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.31k stars 17.7k forks source link

x/tools/gopls: support change signature refactoring #38028

Open stamblerre opened 4 years ago

stamblerre commented 4 years ago

See https://github.com/microsoft/vscode-go/issues/3122 for the original request.

Is your feature request related to a problem? Please describe. I use IntelliJ and VS Code - both for development. VS Code usually for my open source contributions. I noticed that IntelliJ has this cool feature to change the definition / signature of a method or a function - where one can change the parameter's type, add a parameter with a default value for all the callers, and change the return parameters too

Describe the solution you'd like VS Code to provide the feature to change the definition / signature of a method or function, which changes all the references of the method or function based on the change

Describe alternatives you've considered Some features of the change signature feature can still be used currently - For example changing the name of the parameters - which will only cause a change inside the method or function and it can be done by doing just a rename. Other than that, the only alternate solution for me now is - to find all the references and change all the callers to add a parameter and do something similar for other things too.

Additional context It would be cool for VS code to provide this feature. Not sure how it will be implemented. Is this a feature that should be provided by gopls? And if help is needed, I can pitch in - raise some PRs. I need to learn some stuff, which I can surely do. It would be a pleasure to raise PR for one of the greatest extensions for Golang 😄

stamblerre commented 4 years ago

We could also use change signature as a suggested fix for the fillreturns analyzer.

/cc @joshbaum

nvinuesa commented 4 years ago

I would greatly appreciate this feature! thanks for your work on gopls by the way :slightly_smiling_face:

goblinfactory commented 3 years ago

(PING/KEEPALIVE) Hi guys ...any news on this feature? Given that GO doesnt have method overloads, this is a super critical need, since you cannot get away with search and replace to make these refactorings with a text editor/grep etc. Seems a bit overkill to have 1 person in the dev team manage all method refactorings with a single goland licence.

This thread looks dead, (no movement since October 2020) does this mean that as a noobie GOLANG user I've missed something (obvious to the wise grey haired folk) that makes this a non issue?

please advise...txs, Alan

findleyr commented 1 year ago

FWIW this is now very feasible as a result of the inlining work @adonovan has been doing (e.g. #62650): a change signature refactoring can be implemented using inlining by creating a synthetic callee with the new signature, delegating the body of the current callee to the synthetic callee, and inlining the current callee.

In other words, Alan has done all the really hard (surprisingly hard) work of making inlining correct and safe, and change signature refactoring is now "just bookkeeping"...

Of course, it's not quite that easy:

gopherbot commented 8 months ago

Change https://go.dev/cl/572296 mentions this issue: gopls/internal/golang: support removing unused parameters from methods

gopherbot commented 1 week ago

Change https://go.dev/cl/581535 mentions this issue: gopls/internal/golang: support parameter movement refactorings

gopherbot commented 5 days ago

Change https://go.dev/cl/631296 mentions this issue: gopls/internal/golang: change signature via renaming 'func'