Skip to content

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

Open

Description

@stamblerre

See microsoft/vscode-go#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 😄

Activity

  1. added
    FeatureRequestIssues asking for a new feature that does not need a proposal.
    goplsIssues related to the Go language server, gopls.
    ToolsThis label describes issues relating to any tools in the x/tools repository.
    on Mar 23, 2020
  2. added this to the Unreleased milestone on Mar 23, 2020
  3. stamblerre commented on Jun 5, 2020

    @stamblerre
    ContributorAuthor

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

    /cc @joshbaum

  4. removed this from the Unreleased milestone on Jul 23, 2020
  5. nvinuesa commented on Sep 9, 2020

    @nvinuesa

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

  6. added this to the gopls/unplanned milestone on Oct 21, 2020
  7. goblinfactory commented on Sep 3, 2021

    @goblinfactory

    (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

  8. findleyr commented on Sep 27, 2023

    @findleyr
    Contributor

    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.
  9. 4 remaining items

  10. added this to the gopls/v0.17.0 milestone on May 23, 2024
  11. gopherbot commented on Nov 19, 2024

    @gopherbot
    Contributor

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

  12. gopherbot commented on Nov 22, 2024

    @gopherbot
    Contributor

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

  13. findleyr commented on Dec 13, 2024

    @findleyr
    Contributor

    gopls@v0.17.0 supports parameter movement refactoring. Moving this to v0.18.0 for the rest: parameter addition and result transformation.

  14. djahandarie commented on Feb 11, 2025

    @djahandarie

    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

    	tests := map[string]struct {
    		fields  fields
    		args    args
    		want    []string
    		wantErr bool
    	}{
    

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FeatureRequestIssues asking for a new feature that does not need a proposal.RefactoringIssues related to refactoring toolsToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions