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: limited cross references when using with vscode on Go repo #41633

Closed
thanm opened this issue Sep 25, 2020 · 5 comments
Closed
Labels
FrozenDueToAge 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

@thanm
Copy link
Contributor

thanm commented Sep 25, 2020

What version of Go are you using (go version)?

$ go version
$ go version
go version go1.15.2 linux/amd64
$ gopls version
golang.org/x/tools/gopls v0.5.0
    golang.org/x/tools/gopls@v0.5.0 h1:XEmO9RylgmaXp33iGrWfCGopVYDGBmLy+KmsIsfIo8Y=

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/local/google/home/thanm/.cache/go-build"
GOENV="/usr/local/google/home/thanm/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/tmp/gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/tmp/gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/tmp/go.repo"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/tmp/go.repo/pkg/tool/linux_amd64"
GCCGO="/ssd/gcc-trunk/cross/bin/gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/go.repo/src/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-build118750431=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I am trying to use vscode to develop the Go standard library, as described in https://github.com/golang/vscode-go/blob/master/docs/stdlib.md. While I am able to get vscode up and running, I can't seem to get the correct set of cross references for exported package symbols.

I've attached a small shell script that checks out and builds Go stdlib and gopls, then invokes vscode in the proper spot. In the vscode session, I navigate to /src/cmd/internal/goobj2/objfile.go, then select the symbol PkgIdxSelf on line 142, and then select "Find All References".

What did you expect to see?

A similar operation using "guru" returns this set:

/tmp/go.repo/src/cmd/internal/goobj2/objfile.go:143.2-143.11: references to const PkgIdxSelf untyped int
/tmp/go.repo/src/cmd/internal/goobj/readnew.go:63.15-63.24: case goobj2.PkgIdxSelf:
/tmp/go.repo/src/cmd/internal/goobj/readnew.go:131.33-131.42: if a.Sym().PkgIdx != goobj2.PkgIdxSelf {
/tmp/go.repo/src/cmd/internal/obj/objfile2.go:336.56-336.65: case goobj2.PkgIdxNone, goobj2.PkgIdxBuiltin, goobj2.PkgIdxSelf: // not an external indexed reference
/tmp/go.repo/src/cmd/internal/obj/objfile2.go:437.19-437.28: PkgIdx: goobj2.PkgIdxSelf,
/tmp/go.repo/src/cmd/internal/obj/objfile2.go:452.22-452.31: s.PkgIdx = goobj2.PkgIdxSelf
/tmp/go.repo/src/cmd/internal/obj/sym.go:197.22-197.31: s.PkgIdx = goobj2.PkgIdxSelf
/tmp/go.repo/src/cmd/link/internal/loader/loader.go:600.14-600.23: case goobj2.PkgIdxSelf:
/tmp/go.repo/src/cmd/compile/internal/gc/iexport.go:1002.27-1002.36: if lsym.PkgIdx > goobj2.PkgIdxSelf || (lsym.PkgIdx == goobj2.PkgIdxInvalid && !lsym.Indexed()) || s.Linkname != "" {

What did you see instead?

Only returns references in the source file (objfile.go).

vscode-xref-repro-shellscript.txt

@thanm thanm 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 Sep 25, 2020
@gopherbot gopherbot added this to the Unreleased milestone Sep 25, 2020
@heschi
Copy link
Contributor

heschi commented Sep 25, 2020

The problem here is that cmd is actually a separate module from the normal standard library, so you need to use src/cmd as the workspace folder in VS Code. That is, change the lastish line of the shell script from code . to code cmd.

Sorry for the trouble. We are actively working on multi-module workspaces, which we're expecting will get this working automatically.

@thanm
Copy link
Contributor Author

thanm commented Sep 25, 2020

Thanks Heschi -- makes sense. Appreciate the help; I'll close out the bug.

@thanm thanm closed this as completed Sep 25, 2020
@dr2chase
Copy link
Contributor

Does .vscode need to be moved into src/cmd also?

@heschi
Copy link
Contributor

heschi commented Sep 25, 2020

Yes.

@dr2chase
Copy link
Contributor

and lo, it worked. Thanks.

@golang golang locked and limited conversation to collaborators Sep 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

4 participants