Skip to content

Generate constructors command similar to Generate interface stubs #2507

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
tjgurwara99 opened this issue Oct 23, 2022 · 4 comments
Open

Generate constructors command similar to Generate interface stubs #2507

tjgurwara99 opened this issue Oct 23, 2022 · 4 comments
Labels
FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.

Comments

@tjgurwara99
Copy link

tjgurwara99 commented Oct 23, 2022

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

No, I guess it's based off of convenience rather than a problem - it relates to development productivity really so it might be considered a problem but not sure I'd personally define it as a problem.

Anyways, I was wondering if there are any plans to add the capability of generating constructors for a given type from the command palette - similar to how the "generate interface stubs" (based on impl tool) or "generate unit tests" works.

Describe the solution you'd like

Often times, people write constructors such as NewXxx for type a Xxx. A similar utility to generate constructors exists in the GoLand IDE and I think it would help boost peoples productivity when working on Go codebases in VSCode.

Describe alternatives you've considered

I currently have a working command line utility written in Go that does this exact same thing but as its a command line program I have to context switch to that and use the terminal to run the program (plus I whipped it up quickly to suit my needs so can't say its production quality). I believe a production quality utility like this would benefit the Go community a lot if something like that exists in the official Go extension.

Additional context

I have a working PoC for it, which you can find on my fork of this repository here 😄. The diff can be seen here - in case it is useful.

@gopherbot gopherbot added this to the Untriaged milestone Oct 23, 2022
@tjgurwara99 tjgurwara99 changed the title Generate constructors Generate constructors command similar to Generate interface stubs Oct 23, 2022
@dle8 dle8 modified the milestones: Untriaged, vscode-go/unplanned Oct 26, 2022
@dle8 dle8 added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 26, 2022
@hyangah
Copy link
Contributor

hyangah commented Oct 27, 2022

Looks like the actual functionality is implemented by using another tool github.com/tjgurwara99/constr
I don't think it's a good idea to add another external tool dependency just for this feature. Instead, is it possible to add this feature in the gopls? (maybe as a code action or a custom command)

@tjgurwara99
Copy link
Author

I wasn't saying that you should use my solution but rather it is a request to add something similar to what I already have in the official go extension because I sincerely believe it would be beneficial for a lot of people 😄

actual functionality is implemented by using another tool github.com/tjgurwara99/constr

On this, I believe that my solution is no different from the tool impl that is being used to generate the interface stubs (look at the Go: Generate interface stubs command on the palette. If you believe that this kind of solution is not correct, then I would argue that impl also shouldn't be used either. Food for thought...

@hyangah
Copy link
Contributor

hyangah commented Oct 28, 2022

Yes, impl is about to be removed from the dependency, in favor of golang/go#37537

@tjgurwara99
Copy link
Author

tjgurwara99 commented Oct 30, 2022

Ah that makes a lot of sense - thanks! Is there documentation on how to work with code actions in gopls anywhere? I couldn't find it anywhere - I did inspect the changes Marwan had implemented here but I didn't understand a lot of it. So I'm guessing that it would be a non issue (hopefully) once I read the documentation 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest 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