Skip to content
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 request: refactor.extract.struct #70715

Open
danp opened this issue Dec 6, 2024 · 3 comments
Open

x/tools/gopls: feature request: refactor.extract.struct #70715

danp opened this issue Dec 6, 2024 · 3 comments
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@danp
Copy link
Contributor

danp commented Dec 6, 2024

in slack

Suppose I have:

type X struct {
  A, B, C, D string
}

and I want to move to:

type Y struct {
  A, B string
}

type X struct {
  Y
  C, D string
}

It would be nice to have some help with that.

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Dec 6, 2024
@gopherbot gopherbot added this to the Unreleased milestone Dec 6, 2024
@findleyr findleyr modified the milestones: Unreleased, gopls/backlog Dec 6, 2024
@findleyr
Copy link
Member

findleyr commented Dec 6, 2024

Thanks, this is a neat idea, and feels like a natural extraction operation to offer.

Thinking about what could be broken by this refactoring:

  • unkeyed literals
  • type conversions
  • certain rare assignments (var x X = struct{A, B, C, D string}{})

Given that any dependency on field layout is discouraged outside the local package, it probably suffices to check for these constraints only in the package(s) defining the type. Note that we don't have to worry about type conversions where the underlying is forwarded (type X2 X).

(Did I miss anything?)

@tttoad
Copy link

tttoad commented Dec 6, 2024

@findleyr
Initialization outside of local packages should be refactored.

a := pkg.X{A: "s", B: "s", C: "s", D: "s"} => a := pkg.X{Y: pkg.Y{A: "s", B: "s"}, C: "s", D: "s"}

@adonovan adonovan added the Refactoring Issues related to refactoring tools label Dec 12, 2024
@adonovan
Copy link
Member

If any field is embedded, the method sets may change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants