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

x/tools/gopls: incorrect package qualification when stubbing method in v2 module #65024

Closed
mohammed90 opened this issue Jan 8, 2024 · 4 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@mohammed90
Copy link

gopls version

v0.14.2

go env

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/mohammed/Library/Caches/go-build'
GOENV='/Users/mohammed/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/mohammed/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/mohammed/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/Cellar/go/1.21.5/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/Cellar/go/1.21.5/libexec/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.21.5'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/mohammed/projects/caddyserver/caddy/go.mod'
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 x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/y4/4f2hpy494s5598r584s_8w0h0000gn/T/go-build593698980=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

There's a module with major version in its module path, namely github.com/caddyserver/caddy/v2. The module declares the interface:

type Module interface {
    CaddyModule() ModuleInfo
}

In a different package within the module, I have a file with the following:

type Something struct{}
var _ caddy.Module = (*Something)(nil)

As expected, vscode-go tells me it that Something does not implement the interface, and suggests to implement caddy.Module. Click on the suggestion to implement (generate stub for) caddy.Module interface.

What did you see happen?

The generated stub implementation was:

func (*Something) CaddyModule() v2.ModuleInfo {
	panic("unimplemented")
}

What did you expect to see?

func (*Something) CaddyModule() caddy.ModuleInfo {
	panic("unimplemented")
}

This is because the package name at the root of the module is caddy, not v2.

Editor and settings

No response

Logs

No response

@mohammed90 mohammed90 added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Jan 8, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jan 8, 2024
@mohammed90
Copy link
Author

The discussion in Gopher Slack mentions this CL as possible culprit: https://go-review.googlesource.com/c/tools/+/469155.

@findleyr findleyr changed the title x/tools/gopls: issue title x/tools/gopls: incorrect package qualification when stubbing method in v2 module Jan 8, 2024
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.16.0 Jan 8, 2024
@findleyr
Copy link
Contributor

findleyr commented Jan 8, 2024

Thanks for filing! CC @adonovan

@adonovan adonovan self-assigned this Jan 8, 2024
@findleyr findleyr modified the milestones: gopls/v0.16.0, gopls/v0.15.0 Jan 8, 2024
@gopherbot
Copy link

Change https://go.dev/cl/554717 mentions this issue: gopls/internal/lsp/source/stub: trim version suffix from module path

@callthingsoff
Copy link
Contributor

Hi, please see https://go-review.googlesource.com/c/go/+/552195,
it failed on (x/tools) linux-amd64: https://storage.googleapis.com/go-build-log/690c1ac6/linux-amd64_be481842.log

--- FAIL: Test (0.40s)
    --- FAIL: Test/suggestedfix/issue65024.txt (1.78s)
        marker_test.go:301: a/v2/b/b.go:7:21 (suggestedfix/issue65024.txt:25:21): suggestedfix: wrong diff for a/v2/b/b.go:
            
            got:
            @@ -7 +7,5 @@
            +// F implements a.I.
            +func (b *B) F() a.T {
            +	panic("unimplemented")
            +}
            +
            @@ -10 +15 @@
            -
            
            
            want:
            @@ -7 +7,5 @@
            +// F implements a.I.
            +func (*B) F() a.T {
            +	panic("unimplemented")
            +}
            +
            @@ -10 +15 @@
            -
            
        marker_test.go:301: a-a/v2/b/b.go:7:19 (suggestedfix/issue65024.txt:58:19): suggestedfix: wrong diff for a-a/v2/b/b.go:
            
            got:
            @@ -3 +3,2 @@
            +import a "testdata/a-a/v2"
            +
            @@ -7 +9,5 @@
            +// F implements a.I.
            +func (b *B) F() a.T {
            +	panic("unimplemented")
            +}
            +
            @@ -10 +17 @@
            -
            
            
            want:
            @@ -3 +3,2 @@
            +import a "testdata/a-a/v2"
            +
            @@ -7 +9,5 @@
            +// F implements a.I.
            +func (*B) F() a.T {
            +	panic("unimplemented")
            +}
            +
            @@ -10 +17 @@
            -
            
FAIL
FAIL	golang.org/x/tools/gopls/internal/test/marker	14.472s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants