Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

impl support to generate method stubs for implementing an interface #259

Closed
OneOfOne opened this issue Mar 21, 2016 · 13 comments
Closed

impl support to generate method stubs for implementing an interface #259

OneOfOne opened this issue Mar 21, 2016 · 13 comments

Comments

@OneOfOne
Copy link
Contributor

Any chance of adding support for impl?

@lukehoban
Copy link
Member

Nice idea. Happy to accept a PR on this.

@OneOfOne
Copy link
Contributor Author

I'll see what I can do when I get some free time.

@ramya-rao-a ramya-rao-a changed the title impl support impl support to generate method stubs for implementing an interface Aug 18, 2016
@itsjamie
Copy link
Contributor

itsjamie commented Mar 1, 2017

As mentioned in #822 here's a little bit of research from the person behind goimpl.

impl is parsing AST, goimpl is using reflection.
impl is much faster and has better error reporting.
goimpl generates complete code that (usually) compiles (package/imports).
goimpl can generate a minimum update for the exising implementation.
goimpl can work with ambiguous package names.

To me after reading the above, I'd rather use impl the code is easier to grok because of AST parse vs loading code with template and then doing reflection. As a user, I wouldn't mind just manually removing any additional methods I already had implemented.

Thoughts? @mattetti @ramya-rao-a

@mattetti
Copy link
Contributor

mattetti commented Mar 1, 2017

interesting comparison, I'd probably go with impl because of the AST and performance. Note also that our good friend @fatih of awesome vim-go has been using impl for a while and therefore vetted it for us :) https://github.com/fatih/vim-go/blob/master/plugin/go.vim#L23

@ramya-rao-a
Copy link
Contributor

impl for the win.

@itsjamie Feel free to submit a PR for this. If you have questions or doubts on how to go about integrating this, I can answer them for you.

@itsjamie
Copy link
Contributor

@ramya-rao-a I put a PR (#939) up that implements the josharian/impl package as a command go.impl.cursor. Couple of feature things in that PR that aren't implemented, but it's very much usable.

@ramya-rao-a
Copy link
Contributor

This is now available in the latest update 0.6.62

@renannprado
Copy link

@ramya-rao-a should it work for interfaces in the same file?

I'm getting the following error: Cannot stub inteface: unrecognized interface: MyInterface

@ramya-rao-a
Copy link
Contributor

@renannprado Did you provide the package name along with the interface?

For example: I had to use f *File stringutil.Boo where Boo is the interface and stringutil is the package name

@Mistobaan
Copy link

This could be very useful if implemented properly. Many values of the method could be inferred from the code. Ideally I would like to have >GO: GEneratate interface for variable at mouse point -> AutoComplete available interfaces for the given package -> ENTER ->

@ramya-rao-a
Copy link
Contributor

@Mistobaan So the advantage over the current method is that you will be able to choose the interface and not remember/type the name of the interface?

@Mistobaan
Copy link

@ramya-rao-a yes. right now if you miss one character of the whole command the prompt resets and you have to type the whole thing again

@ramya-rao-a
Copy link
Contributor

Say you want stubs for the io.Reader interface. You can today type io. and autcomplete will suggest all symbols from the io package.

In this list, for every interface, we can have another entry which when selected, will insert the stubs. Thoughts?

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants