You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
x/tools/gopls: support change signature refactoring #38028
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 😄
Reacted by Gus Eggert, rowe0x, Nicolas, Sven Ulland, Roxy Light, Dylan Barnard, Jacob Bednarz, Shaw Vrana, k4p7, Niklas Paulicks and 48 more
(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
Reacted by kentliuqiao, Chen Dar, rpateldius, Cheng Yang, Adrian Capitanu, Vitaly Karpenko, Chris Cerk, Berkant İpek, Pavel Sturc, kishoregv and 6 more
Reacted by Jaime Cepeda, Omer Tuchfeld, Berkant İpek, mmihira and kishoregv
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:
Working with synthetic AST nodes is always difficult and buggy, due to loss of position information and comment associations.
Due to how inlining is implemented currently, we'd have to type-check the synthetic code, and so would have to first extract it into the callee package.
AFAIK there's no good LSP API for the type of change-signature UX one would presumably want. We could expose a custom command in gopls but would have to write client-side code to bind to that command.
Excited for parameter addition. Especially 0->1 parameters would be great. For example, I often have dozens or hundreds of test cases defined within a map like
but then realize that, for example, one of the tests cases requires want to have some extra context passed and needs to be a function. Currently it's extremely grueling to change the signature of want from []string to func(s string) []string across so many test cases.
Activity
stamblerre commentedon Jun 5, 2020
We could also use change signature as a suggested fix for the fillreturns analyzer.
/cc @joshbaum
nvinuesa commentedon Sep 9, 2020
I would greatly appreciate this feature! thanks for your work on gopls by the way 🙂
goblinfactory commentedon Sep 3, 2021
(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 commentedon Sep 27, 2023
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:
4 remaining items
gopherbot commentedon Nov 19, 2024
Change https://go.dev/cl/581535 mentions this issue:
gopls/internal/golang: support parameter movement refactoringsgopherbot commentedon Nov 22, 2024
Change https://go.dev/cl/631296 mentions this issue:
gopls/internal/golang: change signature via renaming 'func'gopls/internal/golang: support parameter movement refactorings
gopls/internal/golang: change signature via renaming 'func'
findleyr commentedon Dec 13, 2024
gopls@v0.17.0 supports parameter movement refactoring. Moving this to v0.18.0 for the rest: parameter addition and result transformation.
djahandarie commentedon Feb 11, 2025
Excited for parameter addition. Especially 0->1 parameters would be great. For example, I often have dozens or hundreds of test cases defined within a map like
but then realize that, for example, one of the tests cases requires
wantto have some extra context passed and needs to be a function. Currently it's extremely grueling to change the signature ofwantfrom[]stringtofunc(s string) []stringacross so many test cases.