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

Generate interface stubs adds structs parameter with package name #2364

Open
arifmahmudrana opened this issue Jul 21, 2022 · 4 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@arifmahmudrana
Copy link

arifmahmudrana commented Jul 21, 2022

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go1.16.5 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • v0.9.1
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.69.2
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.35.1
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

Generate interface stubs

When generate interface stubs for interface in same file it adds the package name for parameter.
When generate interface stubs for interface in same file it shouldn't add the package name.

Screenshots or recordings

screencast_00000.mp4
@gopherbot gopherbot added this to the Untriaged milestone Jul 21, 2022
@arifmahmudrana arifmahmudrana changed the title Generate interface stubs generates interface for the same file with package name Generate interface stubs adds structs parameter with package name Jul 22, 2022
@jamalc jamalc added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 22, 2022
@jamalc jamalc modified the milestones: Untriaged, vscode-go/later Jul 22, 2022
@jamalc
Copy link
Contributor

jamalc commented Jul 22, 2022

Interface stub generation is provided by https://github.com/josharian/impl. There is some discussion around supporting package-local interface in josharian/impl#14. Do you get the expected result if you use the unqualified interface identifier for the input (i.e. "c *categoryResponse CategoryRepository" instead of "c *categoryResponse repo.CategoryRepository" )?

@hyangah
Copy link
Contributor

hyangah commented Jul 22, 2022

Looks like this is the old way of generating interface stub (that's based on impl tool, not gopls)

If you generate the stub using the gopls's code action (see below), do you still observe the same issue?

Screen Shot 2022-07-22 at 2 02 15 PM
)

(note: this gopls-based workflow currently requires some hints. For example, in my screenshot, I gave a dummy var _ I = &c{}. Another way is to start using c where I is expected.)

I still feel this gopls-based workflow is harder to find compared to the original command-style implementation. In
golang/go#37537 and golang/go#37537 (comment) we discussed possibility of supporting this workflow. I know it was blocked on work for better known packages/interfaces discovery. @marwan-at-work @findleyr Is there an open issue to follow up the progress?

@arifmahmudrana
Copy link
Author

arifmahmudrana commented Jul 22, 2022

Interface stub generation is provided by https://github.com/josharian/impl. There is some discussion around supporting package-local interface in josharian/impl#14. Do you get the expected result if you use the unqualified interface identifier for the input (i.e. "c *categoryResponse CategoryRepository" instead of "c *categoryResponse repo.CategoryRepository" )?

@jamalc I get this error

Cannot stub interface: unrecognized interface: CategoryRepository

@arifmahmudrana
Copy link
Author

Looks like this is the old way of generating interface stub (that's based on impl tool, not gopls)

If you generate the stub using the gopls's code action (see below), do you still observe the same issue?

Screen Shot 2022-07-22 at 2 02 15 PM )

(note: this gopls-based workflow currently requires some hints. For example, in my screenshot, I gave a dummy var _ I = &c{}. Another way is to start using c where I is expected.)

I still feel this gopls-based workflow is harder to find compared to the original command-style implementation. In golang/go#37537 and golang/go#37537 (comment) we discussed possibility of supporting this workflow. I know it was blocked on work for better known packages/interfaces discovery. @marwan-at-work @findleyr Is there an open issue to follow up the progress?

@hyangah Yes this works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants