Open zejunlitg opened 2 years ago
@adonovan
Gopls only finds the references on package level, not on module level.
FWIW, this is not what I observe, and is certainly not the intended behavior. Gopls should find all references within any workspace packages. In other words, if opening up a module root, gopls should find all references contained in any package inside the module. (golang/go#43144 catalogs a known bug about references in test variants, but that doesn't seem to be what is reported here).
It may be that somehow gopls is failing to compute workspace packages correctly. A more specific reproducer would be helpful.
@findleyr Hi, Does
Find all references
only consider opened packages? Is this the expected behavior? The global search feature of vscode can find all function reference just fine, so I'm curious.
No, find all references should consider all workspace packages. If you do not see this happening, it is either a bug or a misconfiguration (or both). If you had a small reproducer, or could share LSP logs, it would help us understand what is going on in your session.
No, find all references should consider all workspace packages. If you do not see this happening, it is either a bug or a misconfiguration (or both). If you had a small reproducer, or could share LSP logs, it would help us understand what is going on in your session.
I don't really have a minimal reproducer, but I do have a workspace error, could that be related?
Also, where do I find LSP logs, where are they located?
I don't really have a minimal reproducer, but I do have a workspace error, could that be related?
Yes, that is almost certainly related. What is your workspace error?
Instructions for how to collect logs are here: https://github.com/golang/vscode-go/blob/master/docs/troubleshooting.md#collect-gopls-information
I don't really have a minimal reproducer, but I do have a workspace error, could that be related?
Yes, that is almost certainly related. What is your workspace error?
Instructions for how to collect logs are here: https://github.com/golang/vscode-go/blob/master/docs/troubleshooting.md#collect-gopls-information
err: exit status 1: stderr: build github.com/...: cannot load github.com/...: import lookup disabled by -mod=readonly
: packages.Load errorgo list
Just created another playground using go module and the find all references seem to work as expected, but my actual working repo is still not working
I don't really have a minimal reproducer, but I do have a workspace error, could that be related?
Yes, that is almost certainly related. What is your workspace error?
Instructions for how to collect logs are here: https://github.com/golang/vscode-go/blob/master/docs/troubleshooting.md#collect-gopls-information
[Trace - 23:56:38.654 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2022/09/08 23:56:38 go/packages.Load #2: updating metadata for 593 packages\n"}
if a function in package A has been referenced in both package B and C, if I open a file where it referenced this function in package B, then Find all references
can find all references in package B, but still missing all the references in package C.
This is the only way I discovered to make Find all references
actually find references in other packages.
This error is surprising: cannot load github.com/...
.
Do you have a module path named "github.com" in your workspace?
This error is surprising:
cannot load github.com/...
.Do you have a module path named "github.com" in your workspace?
Yes, we're using module mod, this is some package inside our module, I can confirm 'Find all reference' only works after I open certain packages, I deliberately leave only one file open and when the packages are loaded(except for this workspace error), find all reference only finds itself, but after I open other packages where this function is referenced, those references are found as well.
Yes, we're using module mod
Sorry, I don't understand. Do you have a go.mod
file containing module github.com
somewhere?
Yes, we're using module mod
Sorry, I don't understand. Do you have a
go.mod
file containingmodule github.com
somewhere?
I do, there is a go.mod file, it's in the root directory of this repo.
Gopls is having trouble loading your workspace. Does go list ./...
from your repo root succeed for you?
Are you able to share the full logs from a gopls session?
Gopls is having trouble loading your workspace. Does
go list ./...
from your repo root succeed for you?Are you able to share the full logs from a gopls session?
It seems so, go list ./...
does work, I can't share the full logs as this is NDA codebase.
For now I simply don't use Find all references
as its behavior is not as expected, I just use global search.
this happens for me also. smaple project structure:
testgo.code-workspace:
{
"folders": [
{
"path": "moda"
},
{
"path": "modb"
}
],
}
moda/go.mod
module github.com/test/moda
go 1.19
moda/a.go
package moda
import "fmt"
func TestFunc1() {
fmt.Println("test")
}
modb/go.mod
module github.com/test/modb
go 1.19
replace github.com/test/moda => ../moda/
require github.com/test/moda v0.0.0-00010101000000-000000000000
modb/main.go
package main
import "github.com/test/moda"
func main() {
moda.TestFunc1()
}
when doing "Find All References" in moda
it cant find modb
references,
but if i use "Find All References" in modb
if finds all references.
have the same issue here. is there any workaround?
Try the following commands from your workspace directory:
go work init
go work use .
This worked for me.
What version of Go, VS Code & VS Code Go extension are you using?
go version go1.13.15 linux/amd64
vscode:
Version: 1.70.2 (Universal)
Version Information
* Run `go version` to get version of Go from _the VS Code integrated terminal_. -
Share the Go related settings you have added/edited
see below
Run
Preferences: Open Settings (JSON)
command to open your settings.json file. Share all the settings with thego.
or["go"]
orgopls
prefixes.Describe the bug
Bug description: Gopls only finds the references on package level, not on module level.
References in other packages can be found/peeked ONLY AFTER I opened certain package and see the reference,
which is useless, because the point of finding all references is it finds all references for me without needing to open all the packages.
What I expect: Find all reference finds all references of a function on a module level, it should search all the packages in this module.
Steps to reproduce the behavior:
Use
Find all references
allPeek references
feature on any function in a Go project using go module mode, this happens.Screenshots or recordings
N/A