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: offer a quickfix to define a struct field on "has no field or method" error #70217

Open
dennypenta opened this issue Nov 6, 2024 · 6 comments
Labels
FeatureRequest 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

@dennypenta
Copy link

gopls version

v0.16.2

go env

-

What did you do?

Having a cursor on a non defined field doesn't suggest a quickfix to declare a new struct field.
Recently a similar feature was merged #69692 to define a missing method.
However, the ability to make a field is missing.
Screenshot 2024-11-06 at 09 07 37

What did you see happen?

no action suggested
Screenshot 2024-11-06 at 09 07 48

What did you expect to see?

A suggested quick fix "Define a struct field" exists and create a field
Screenshot 2024-11-06 at 09 08 09

Editor and settings

Logs

@dennypenta dennypenta 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 Nov 6, 2024
@gopherbot gopherbot added this to the Unreleased milestone Nov 6, 2024
@adonovan
Copy link
Member

adonovan commented Nov 6, 2024

Sure, that seems like a reasonable feature.

@dennypenta
Copy link
Author

great, I will start the implementation taking the issue I mentioned into account as an example.
I didn't investigate the codebase deep enough, but the plan is the following:

  • I handle the same message "has no field or method"
  • define a struct field info and pass this message to the code action
  • define a fixer and apply it

I couldn't find a similar GetCallStubInfo for structs, if Im just seeking poorly pls let me know

@xzbdmw
Copy link

xzbdmw commented Nov 6, 2024

I handle the same message "has no field or method"

There is probably another case to consider:

f := Foo{
    a: 3, // unknown field a in struct literal of type Foo
}

This can be one more case for TypesFromContext, I've add
more in golang/tools#538, maybe you can
take a look.

@dennypenta
Copy link
Author

dennypenta commented Nov 6, 2024

@xzbdmw thanks, would be useful to extract the type properly.
I will rebase on your branch then.
I anticipate we should create another issue for unknown field, will do as soon as finish with this, because half of the solution can be reused.

@xzbdmw
Copy link

xzbdmw commented Nov 7, 2024

@dennypenta You don’t need to rebase! I will rebase on yours if your cl merge first :)

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. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

7 participants