Skip to content

x/tools/gopls: Add a source code action to regenerate cgo definitions. #73482

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
firelizzard18 opened this issue Mar 9, 2025 · 8 comments
Open
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@firelizzard18
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I'm always annoyed when I'm writing Go that calls C and I have to scroll up to the top of the file to click regenerate cgo definitions whenever I use a C definition I haven't used previously.

Describe the solution you'd like
When I type C.FooBar and FooBar is not yet defined I'd like a quick action to appear so I can use [Ctrl]+. to easily regenerate cgo definitions.

Describe alternatives you've considered
Adding a command to execute regenerate cgo definitions so I can bind that to a key sequence, but that command doesn't exist AFAIK.

Additional context
Image

@h9jiang
Copy link
Member

h9jiang commented Mar 12, 2025

This gopls.regenerate_cgo is exposed from gopls. Is you request to have a wrapper command over the gopls.regenerate_cgo?

Because I think it would be best if the command have the exact same behavior as gopls.regenerate_cgo code lenses. We can figure out the argument required to run gopls.regenerate_cgo then have the wrapper command call gopls to regenerate cgo.

@h9jiang h9jiang added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 12, 2025
@firelizzard18
Copy link
Contributor Author

firelizzard18 commented Mar 12, 2025

That would work for me, though my ideal solution is a quick action (the lightbulb)

@firelizzard18
Copy link
Contributor Author

The correct name for quick action is quick pick or code action, which I believe could be provided directly from gopls.

@firelizzard18 firelizzard18 removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 30, 2025
@findleyr
Copy link
Member

findleyr commented Apr 4, 2025

So the request here is to add a code action over any undefined C symbol, to regenerate cgo definitions.

I'm not sure. Usually, the semantics for quick fixes is that they should have an (almost) guaranteed fix. In this case, the fix depends on C definitions.

We could add a source action; since source actions are meant to apply to the current file, that would make sense. WDYT?

@findleyr
Copy link
Member

findleyr commented Apr 4, 2025

CC @adonovan

I don't think a quick fix is approprate, but either a wrapper command or source action would be reasonable.
My preference is a source action, since it benefits all editors. @firelizzard18 if you agree, we'll move this to the gopls repo and mark it help-wanted, as it should be a relatively trivial fix.

@firelizzard18
Copy link
Contributor Author

My preference is a source action, since it benefits all editors.

That's fine with me, I added a keybind for the source action command so that will solve my problem (being able to regenerate definitions easily).

For my edification, what's the difference between source actions and code actions? Obviously vscode uses a different UI for them but if I were adding functionality to gopls it's not clear to me which I should use. Is the difference simply whether the action is attached to a specific line of code or symbol?

@adonovan
Copy link
Member

adonovan commented Apr 4, 2025

what's the difference between source actions and code actions? Obviously vscode uses a different UI for them but if I were adding functionality to gopls it's not clear to me which I should use. Is the difference simply whether the action is attached to a specific line of code or symbol?

A Code Action is the umbrella term for "a thing you can do to a selected piece of text"; the CodeAction request returns the set of available actions. According to the protocol spec, the source.* kinds are for actions that "apply to the entire file", though gopls disregards that: we use them for anything that's not a refactoring. Some language servers seem to interpret source actions as "typing assistance", such as inserting new skeletal declarations (loops, methods, etc) into the code. Perhaps the only thing we can really say about them with any confidence is "they appear in the Source Action... menu in VS Code".

@h9jiang h9jiang changed the title Add a quick action to regenerate cgo definitions. Add a source code action to regenerate cgo definitions. Apr 23, 2025
@h9jiang h9jiang transferred this issue from golang/vscode-go Apr 23, 2025
@h9jiang h9jiang added this to the gopls/backlog milestone Apr 23, 2025
@h9jiang h9jiang added the FeatureRequest Issues asking for a new feature that does not need a proposal. label Apr 23, 2025
@h9jiang
Copy link
Member

h9jiang commented Apr 23, 2025

Comment updated. Since this is about source code action, I have moved it to gopls milestone.

@seankhliao seankhliao changed the title Add a source code action to regenerate cgo definitions. x/tools/gopls: Add a source code action to regenerate cgo definitions. Apr 23, 2025
@JunyangShao JunyangShao added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Apr 24, 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. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

5 participants