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

please use CodeAction for related code generation #2630

Open
sslime336 opened this issue Jan 29, 2023 · 3 comments
Open

please use CodeAction for related code generation #2630

sslime336 opened this issue Jan 29, 2023 · 3 comments

Comments

@sslime336
Copy link

sslime336 commented Jan 29, 2023

Is your feature request related to a problem? Please describe.

Umm... no? The snippet like meth is helpful but I think below looks better.

Describe the solution you'd like

Like rust-analyzer and Goland, we can simply press Ctrl + . or Alt + Enter to generate a method of our own data structure.

RA(rust-analyzer):

ra_codeaction_gen

Goland:

goland_codeaction_gen

Describe alternatives you've considered
None.

Additional context

Actually I've written some very simple code to achieve this for fun, but my code is in poor quality and I am very new to vscode extension dev!

myex_codeaction_gen_v2

My fork, coded so poor :P

@gopherbot gopherbot added this to the Untriaged milestone Jan 29, 2023
@hyangah
Copy link
Contributor

hyangah commented Feb 2, 2023

Thanks for filing feature requests @sslime336
I see three different code actions

@sslime336
Copy link
Author

sslime336 commented Feb 2, 2023

yeah, using CodeActions, I mean, just press Ctrl plus "." or Alt + Enter like Goland and select the options we needed may be more convenient :)

Actually I haven't thought about generateing a struct from an interface as you mentioned :P, that's a possible option (but I don't know how to find out where to generate the struct that will impl the selected interface, especially when the interface is in a read-only file, we need to figure out the correct place)

Currently, I have these ideas where the CodeAction can be used:

  1. Generate methods from an exist user defined type, just like my demo.
  2. Implement an interface for an exist user defined type (firstly it will invoke a quick pick like in the issues you mentioned).
  3. Implement an interface for an user defined type, but the CodeAction will be invoked from a local or global variable.
  4. As you first pointed, "generates a struct type" from an exist interface.

I'm not familiar with gopls so currently I could only think the ways to impl these features using TypeScript. But I'd like to learn more and mk a contribution as I depend on vscode-go seriously :-)

@gopherbot
Copy link
Collaborator

Change https://go.dev/cl/468658 mentions this issue: src/goGenerateMethod: make method generation more automatic

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

No branches or pull requests

4 participants