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

Feature Request: Better interface stubbing #1741

Closed
matthewmueller opened this issue Jun 19, 2018 · 7 comments
Closed

Feature Request: Better interface stubbing #1741

matthewmueller opened this issue Jun 19, 2018 · 7 comments

Comments

@matthewmueller
Copy link

matthewmueller commented Jun 19, 2018

It can be hard to get the input right with the current implementation of Generate Interface Stubs.

For example, if your path is github.com/matthewmueller/graphql and you have a Query interface and you want your query struct to implement it:

package graphql

// interface to implement
type Query interface {
  CreateTeam(ctx context.Context, teamInput TeamInput) (Team, error)
  // ... many more
}

// this struct needs to implement the Query interface
type query struct {}

// interface enforcement
var _ Query = (*query)(nil)

With the Generate Interface Stubs, you'd need to write in the following:

q *query github.com/matthewmueller/graphql.Query

This is quite hard to get right. I think it'd be a lot more useful if it did the following:

  1. Highlight over the interface enforcement with your cursor: var _ Query = (*query)(nil)
  2. Right click, and click on Generate Interface Stubs
  3. It calls impl under the hood with the correct paths. The receiver variable could just be the first letter of the struct (lowercased)
  4. The output is written below your cursor selection

Update: Even better would be how typescript does it with the little lightbulb next to any interface enforcement that is currently erroring out.

prism4time added a commit to prism4time/vscode-go that referenced this issue Aug 21, 2018
* auto complete for package name
* manual search for interface if the input is unavailable
* allow user to select type name and use right click to get the type
name autocompleted
@prism4time
Copy link
Contributor

@matthewmueller could you describe your demand more specific with your directory structure and the path of your project? I would like to take this issue but it seems you just need to type in graphql.Query instead of github.com/matthewmueller/graphql.Query , the current implemantation in vscode -go extension which make use of impl seems to perform the same with github.com/matthewmueller/graphql.Query and graphql.Query

@prism4time
Copy link
Contributor

If you put your project under $GOPATH directory, impl will automatically search it and you just need to type in the package name without its previous path if it is not ambiguous with another package

@matthewmueller
Copy link
Author

matthewmueller commented Aug 24, 2018

@qzyse2017 awesome! I'm not able to reproduce needing the full path, maybe I was typing in the command wrong. that's definitely easier.

either way, I think it would be really cool if it could auto implement: var _ Query = (*query)(nil)

@prism4time
Copy link
Contributor

@matthewmueller I am doing it in a similar way to what you need.
It just needs to

  1. select the reciever type name and use right click to choose the command Generate interface stub , the inputbox will have the t *typeReciever(something like it) auto completed

  2. type in the last arg: packageName.interfaceName(packageName here do not need its previous path)

  3. relocate your cursor to find the correct place to insert and type in Enter in the inputBox to confirm the command,

I think steps above can be used in more general conditions.
can you give me some more suggestions on making it more easier to use?

@zhulingbiezhi
Copy link

Nice, looking forward to this issuer.

@BitPhinix
Copy link

It would also be nice if vscode would provide interface stubbing as a quick fix.

func NewRepository(db orm.DB) goal.Repository {
	return &Repository{
		db: db,
	}
}

Should provide a quick fix like "generate interface stubs" if Repository doesn't implement goal.Repository

@stamblerre
Copy link
Contributor

Feature work in this area will be done in gopls rather than in this extension. I'm going to close this in favor of the upstream issue, golang/go#37537.

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

6 participants