Skip to content

x/tools/gopls: handle undefined struct type in undeclaredname autofix code action #69947

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

Open
phiros opened this issue Oct 20, 2024 · 5 comments
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@phiros
Copy link

phiros commented Oct 20, 2024

gopls version

golang.org/x/tools/gopls v0.16.2

go env

not relevant

What did you do?

I ran an autofix code action for an undefined struct.

image

What did you see happen?

gopls generated a new variable instead of a struct type definition.
This is nonsensical from a user point of view & also doesn't compile.

image

What did you expect to see?

A struct type definition above the function body.

image

Editor and settings

No response

Logs

No response

@phiros phiros added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Oct 20, 2024
@gopherbot gopherbot added this to the Unreleased milestone Oct 20, 2024
@phiros
Copy link
Author

phiros commented Oct 20, 2024

Note that I already have a fix ready for the above issue that modifies the undeclaredname analyzer.
My understanding is that I have to create this issue first before submitting the change.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/621295 mentions this issue: gopls: handle undefined struct type in undeclaredname

@adonovan
Copy link
Member

Note that I already have a fix ready for the above issue that modifies the undeclaredname analyzer.
My understanding is that I have to create this issue first before submitting the change.

Generally one should also wait for consensus that the feature is useful, but in this case I agree that it is. Thanks for contributing.

@findleyr
Copy link
Member

Thanks for contributing this feature! I'll put this in the [email protected] milestone, assuming it lands expediently.

@findleyr findleyr added the FeatureRequest Issues asking for a new feature that does not need a proposal. label Oct 24, 2024
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.17.0 Oct 24, 2024
@findleyr findleyr modified the milestones: gopls/v0.17.0, gopls/backlog Nov 5, 2024
@adonovan adonovan removed their assignment Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. gopls Issues related to the Go language server, gopls. 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