golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.03k stars 17.67k forks source link

x/tools/gopls: find references from the module cache does not return an implementation in the workspace #47660

Closed pavlelee closed 3 years ago

pavlelee commented 3 years ago

For asking questions, see:

Before filing an issue, please review our troubleshooting guides

Please answer these questions before submitting your issue. Thanks!

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

go env Workspace Folder (vscode-go-test): /data/go/src/github.com/pavlelee/vscode-go-test GO111MODULE="auto" GOARCH="amd64" GOBIN="" GOCACHE="/root/.cache/go-build" GOENV="/root/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="git.code.oa.com,git.woa.com" GOMODCACHE="/data/go/pkg/mod" GONOPROXY="git.code.oa.com,git.woa.com" GONOSUMDB="git.code.oa.com,git.woa.com" GOOS="linux" GOPATH="/data/go" GOPRIVATE="git.code.oa.com,git.woa.com" GOPROXY="https://goproxy.cn,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.16.7" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/data/go/src/github.com/pavlelee/vscode-go-test/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2545995983=/tmp/go-build -gno-record-gcc-switches"


### Share the Go related settings you have added/edited

Run `Preferences: Open Settings (JSON)` command to open your settings.json file.
Share all the settings with the `go.` or `["go"]` or `gopls` prefixes.

{ "go.addTags": { "promptForTags": true }, "go.autocompleteUnimportedPackages": true, "go.buildFlags": [ "-race" ], "go.delveConfig": { "debugAdapter": "dlv-dap", "showGlobalVariables": true }, "go.docsTool": "gogetdoc", "go.formatTool": "goimports", "go.gotoSymbol.includeGoroot": true, "go.gotoSymbol.includeImports": true, "go.languageServerFlags": [ "-remote=auto" ], "go.lintTool": "golangci-lint", "go.testFlags": [ "-race" ], "go.toolsManagement.autoUpdate": true, "go.useCodeSnippetsOnFunctionSuggest": true, "go.useLanguageServer": true, "gopls": { "allExperiments": true }, }



### Describe the bug
vscode-go can't find all references in dependent modules, in my project to find all references of dependent module function, not found references.
![image](https://user-images.githubusercontent.com/5382358/128979367-fd481a29-ed27-425c-9686-0e67a00a7719.png)

But open dependent module in vscode, find one references
![image](https://user-images.githubusercontent.com/5382358/128979382-2d8c30d1-4531-4f24-90c3-701a892c4fed.png)

### Steps to reproduce the behavior:
1. git clone https://github.com/pavlelee/vscode-go-test/tree/master
2. Find Implementations https://github.com/pavlelee/vscode-go-test/blob/5bb76fe53128163d4d6ff4029997112f26553ad7/pkg/provider.go#L30
3. find all references APIProvider.PreCreate
4. see results

### Screenshots or recordings
![image](https://user-images.githubusercontent.com/5382358/128979367-fd481a29-ed27-425c-9686-0e67a00a7719.png)
![image](https://user-images.githubusercontent.com/5382358/128979382-2d8c30d1-4531-4f24-90c3-701a892c4fed.png)
stamblerre commented 3 years ago

Thanks for filing this issue, but unfortunately, I am not able to reproduce it using your sample repo, as it only contains one file. I'm also not totally sure I understand the issue here. Can you please explain it a bit further?

pavlelee commented 3 years ago

@stamblerre 屏幕录制2021-08-12 上午10

But tkestack/tke realy has references, look this:

stamblerre commented 3 years ago

Thanks for the clarification. In this instance, "Find all implementations" does have the reference, but find references doesn't. This is not a high priority issue, but we'll investigate it when possible. Transferring to gopls repository.

pavlelee commented 3 years ago

For gopls, should be higher priority. Because it reduces development efficiency. @stamblerre

pavlelee commented 3 years ago

The core problem is open tkestack,"Find all implementations" is work. But open tkestack from the dependent module, "Find all implementations" is not work. Maybe you understand to "Find all implementations" and "Find implementations" results are different?

stamblerre commented 3 years ago

When I tried to reproduce it, "Find all implementations" seemed to work correctly in both directions. From your video, it seems like the issue was "Find references", which does work slightly differently and was only recently adjusted to include implementations.

pavlelee commented 3 years ago

@stamblerre I always use "Find all implementations", not "Find references". my plugin settings is

"go.addTags": {
    "promptForTags": true
},
"go.autocompleteUnimportedPackages": true,
"go.buildFlags": [
    "-race"
],
"go.delveConfig": {
    "debugAdapter": "dlv-dap",
    "showGlobalVariables": true
},
"go.docsTool": "gogetdoc",
"go.formatTool": "goimports",
"go.gotoSymbol.includeGoroot": true,
"go.gotoSymbol.includeImports": true,
"go.languageServerFlags": [
    "-remote=auto"
],
"go.lintTool": "golangci-lint",
"go.lintFlags": [
    "--fast",
    "-v"
],
"go.testFlags": [
    "-race"
],
"go.toolsManagement.autoUpdate": true,
"go.useCodeSnippetsOnFunctionSuggest": true,
"go.useLanguageServer": true,
"gopls": {
    "allExperiments": true
},
➜  vscode-go-test git:(master) go version                                                
go version go1.16.7 linux/amd64
➜  vscode-go-test git:(master) gopls version
golang.org/x/tools/gopls v0.7.1
    golang.org/x/tools/gopls@v0.7.1 h1:Mh3Z8Xcoq3Zy7ksSlwDV/nzQSbjFf06A+L+F8YHq55U=

image image

[Trace - 10:25:31.696 AM] Sending request 'textDocument/codeLens - (101)'.
Params: {"textDocument":{"uri":"file:///data/go/pkg/mod/tkestack.io/tke%40v1.7.0/pkg/platform/provider/cluster/interface.go"}}

[Trace - 10:25:31.697 AM] Received response 'textDocument/codeLens - (101)' in 0ms.
Result: null

[Trace - 10:25:34.793 AM] Sending request 'textDocument/references - (102)'.
Params: {"textDocument":{"uri":"file:///data/go/pkg/mod/tkestack.io/tke%40v1.7.0/pkg/platform/provider/cluster/interface.go"},"position":{"line":52,"character":7},"context":{"includeDeclaration":true}}

[Trace - 10:25:34.844 AM] Received response 'textDocument/references - (102)' in 51ms.
Result: [{"uri":"file:///data/go/pkg/mod/tkestack.io/tke@v1.7.0/pkg/platform/provider/cluster/interface.go","range":{"start":{"line":52,"character":1},"end":{"line":52,"character":10}}}]
stamblerre commented 3 years ago

@stamblerre I always use "Find all implementations", not "Find references". my plugin settings is

In your video above, it seems like you use "Find references" to illustrate the problem. I agree that the issue is with Find references (as you demonstrate by using the gopls references command above), but it's just not yet a high priority for us to address it. We will update this issue when we are able to investigate it.

pavlelee commented 3 years ago

@stamblerre use vscode open https://github.com/kubernetes/kubernetes.git,"Find all implementations" in https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/storage/interfaces.go#L173, Incomplete content detected. I think these two basic implementations should have. It's too much trouble to find yourself. image In Goland Is complete. image If experimentalWorkspaceModule is turned on, it works normally. But such an error will be reported image

pavlelee commented 3 years ago

add build.allowModfileModifications can fix.

I added the following configuration to fix this scenario problem.

"build.experimentalWorkspaceModule": true,
"build.allowModfileModifications": true
stamblerre commented 3 years ago

@pavlelee: Can you please give concrete steps for how to reproduce this in your sample repo? It's not clear to me exactly what the issue is, and it seems like you edited your sample repo recently.

pavlelee commented 3 years ago

@stamblerre step 1: git clone https://github.com/pavlelee/vscode-go-test.git step 2: enable gopls step 3: I want to check the calling relationship: Go to implementation https://github.com/pavlelee/vscode-go-test/blob/d3c8b809c1ebb2457f12bd51a917d035efa7d6b9/pkg/provider.go#L18 Find all references https://github.com/pavlelee/vscode-test-module/blob/master/pkg/provider/interface.go#L5 return only https://github.com/pavlelee/vscode-test-module/blob/master/pkg/provider/cluster.go#L4. In fact, it is also quoted here https://github.com/pavlelee/vscode-test-module/blob/master/pkg/registry/cluster.go#L6

This is just a representative example. My real project cannot be made public

pavlelee commented 3 years ago

@stamblerre any response?

stamblerre commented 3 years ago

It sounds like you are expecting find references to return results within the module cache, since github.com/pavlelee/vscode-test-module is required by the vscode-go-test module. gopls does not work this way--it only returns references that are within your workspace, not within your module cache (which may be very large).

stamblerre commented 3 years ago

I believe this is working as intended, so I don't think that there is an issue here.

pavlelee commented 3 years ago

I agree with you that this is not a problem, it should be an enhancement. Goland has supported it for a long time. Another solution is to use Extension Authoring adds the module cache to the workspace.

stamblerre commented 3 years ago

Another solution is to use Extension Authoring adds the module cache to the workspace.

I would recommend adding the module cache to your workspace, if you need it to be in there. We don't have any plans to support this in gopls, as we believe that most users aren't intending to search their dependency tree when introspecting code.

I'm going to close this issue, as it is working as intended.

pavlelee commented 3 years ago

This PR is also closed, https://github.com/golang/tools/pull/338

stamblerre commented 3 years ago

Yes, as I mentioned above, we will not support adding the module cache to the workspace in gopls, and so we will not merge changes that try to do that.