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

:GoImpl is unable to implement interfaces with embedded interfaces #3687

Closed
AhmedNSidd opened this issue Sep 24, 2024 · 2 comments
Closed

:GoImpl is unable to implement interfaces with embedded interfaces #3687

AhmedNSidd opened this issue Sep 24, 2024 · 2 comments

Comments

@AhmedNSidd
Copy link

What did you do? (required: The issue will be closed when not provided)

In my Golang project, I had a package named service. In this package, I had a file where I was defining two interfaces: InterfaceParent and InterfaceChild. Each were defining their own functions, but the catch was that :InterfaceParent was embedded inside the interface definition of InterfaceChild, so it looked as follows:

type InterfaceParent interface {
     bar()
}

type InterfaceChild interface {
   InterfaceParent
    foo()
}

After this was done, in a different package, I ran :GoImpl m *MockInterfaceChild github.com/organization123/project123/microservice123/service.InterfaceChild, but I ran into the following error:

vim-go: unrecognized interface: service.InterfaceParent

What did you expect to happen?

I expected the :GoImpl m *MockInterfaceChild github.com/organization123/project123/microservice123/service.InterfaceChild to implement placeholders / stubs for the foo() function in InterfaceChild.

What happened instead?

I got an error instead: vim-go: unrecognized interface: service.InterfaceParent

Configuration (MUST fill this out):

vim-go version: ac1fb9611de435d80a6badcf8482cb1428449b10

vimrc you used to reproduce:

vimrc
call plug#begin()

" PLUGINS

"" Plugin for working with Golang projects
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }

call plug#end()

set autowrite

Vim version (first three lines from :version):

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jun 29 2024 05:34:37)
macOS version - arm64
Included patches: 1-2136, 2142

Go version (go version):

go version go1.22.6 darwin/arm64

Go environment

go env Output:
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/ahsiddiqui/Library/Caches/go-build'
GOENV='/Users/ahsiddiqui/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/ahsiddiqui/go/pkg/mod'
GONOPROXY='github.com/equinix-gnae/*'
GONOSUMDB='github.com/equinix-gnae/*'
GOOS='darwin'
GOPATH='/Users/ahsiddiqui/go'
GOPRIVATE='github.com/equinix-gnae/*'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/[email protected]/1.22.6/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/[email protected]/1.22.6/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.6'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/0r/pbc91fld4_3_dsg2cpx90_140000gp/T/go-build2359003490=/tmp/go-build -gno-record-gcc-switches -fno-common'

gopls version

gopls version Output:
golang.org/x/tools/gopls v0.16.2
@AhmedNSidd AhmedNSidd changed the title :GoImpl is unable to implement interfaces with embedded interfaces :GoImpl is unable to implement interfaces with embedded interfaces Sep 24, 2024
@AhmedNSidd
Copy link
Author

I found out that this issue isn't directly related to vim-go so much as it is related to the impl tool that vim-go uses.

Apparently there's been an open-standing ticket for this issue since 2018 in the impl repo: josharian/impl#30

@AhmedNSidd
Copy link
Author

I'll go ahead and close this issue since as mentioned before, this isn't directly related to vim-go, but I will mention that from doing some research online, it looks like there are alternatives to the :GoImpl command which is to use the :GoGenerate command in conjunction with the mockery tool to generate your mocks based off interfaces.

@AhmedNSidd AhmedNSidd closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant