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

ctrl+] behavior does not navigate to symbols in the same module but different source file #2716

Closed
PaulForgey opened this issue Feb 11, 2020 · 24 comments

Comments

@PaulForgey
Copy link

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

Try to navigate to a symbol using ctrl+].

Small reproduction:

filea.go

package foo

type Foo struct {
	x int
}

fileb.go

package foo

import (
	"fmt"
)

type Bar struct {
	a int
}

func DoSomething(f *Foo, b *Bar) {
	// ctrl+] in Bar works (inside this file), Foo does not (inside the package, but not this file)
	fmt.Println("") // Println works (outside this package)
}

What did you expect to happen?

In the example fileb.go, navigate to the symboles Foo, Bar and Println

What happened instead?

Foo is not found, able to navigate to Bar and Println

Configuration (MUST fill this out):

vim-go version:

vimrc you used to reproduce (use a minimal vimrc with other plugins disabled; do not link to a 2,000 line vimrc):

vimrc
set co=132

call plug#begin('~/.vim/plugged')
Plug 'fatih/vim-go', { 'tag': 'v1.22' }
call plug#end()

Vim version (first three lines from :version):

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jan 7 2020 00:59:23)
Included patches: 1-96
Compiled by ubuntu@ip-172-31-37-247

Go version (go version):

go version go1.13.3 linux/amd64

Go environment

go env Output:
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ubuntu/.cache/go-build"
GOENV="/home/ubuntu/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ubuntu/mesa/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/src/go1.13.3/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/src/go1.13.3/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build432119207=/tmp/go-build -gno-record-gcc-switches"

gopls version

gopls version Output:
golang.org/x/tools/gopls v0.3.1
    golang.org/x/tools/gopls@v0.3.1 h1:yNTWrf4gc4Or0UecjOas5pzOa3BL0WDDyKDV4Wz5VaM=

@bhcleek
Copy link
Collaborator

bhcleek commented Feb 11, 2020

The files are outside of GOPATH/src? Does it matter if you have a go.mod file?

@PaulForgey
Copy link
Author

PaulForgey commented Feb 11, 2020

They are not outside GOPATH/src. I am not using go.mod, but I can try to see if that has an effect.

@PaulForgey
Copy link
Author

If I create a go.mod file with the package, navigation does not work at all, not even giving errors.

@bhcleek
Copy link
Collaborator

bhcleek commented Feb 11, 2020

Thanks. Let's focus on the GOPATH mode situation first. I create a quick package that replicates what I understand your description to be and recorded it. I don't see any problems:

recording

I noticed that the vimrc you posted is rather short and doesn't include some things that I would expect to have (e.g. filetype plugin indent on). 🤔

Does it work if you execute :GoDef instead of ctrl+]?

@PaulForgey
Copy link
Author

:GoDef behaves the same as ctrl+]
That's the entirety of the .vimrc. On this system, vim is used exclusively for go code and the vim-go plugin plus the default setup is satisfactory.
My modules are indeed rooted in $GOPATH

@PaulForgey
Copy link
Author

I have another platform running vim-go which was working, where, as an experiment, I cleaned out go/bin and re-ran GoUpdateBinaries to re-install. Now it has the same behavior. I suspect an updated third party module might be to blame.

@bhcleek
Copy link
Collaborator

bhcleek commented Feb 11, 2020

The only binary involved here outside of the go toolchain is gopls.

What's the gopls log output if you add let g:go_debug=['lsp'] to your vimrc and try going to the definition of Foo from fileb.go?

@bhcleek
Copy link
Collaborator

bhcleek commented Feb 11, 2020

I should also point out that you can change g:go_def_mode to use a different tool to jump to definitions.

@PaulForgey
Copy link
Author

{"method":"initialize","jsonrpc":"2.0","id":1,"params":{"rootUri":"file:///home/ubuntu/mesa/go/src/foo","capabilities":{"workspace":{"workspaceFolders":true,"configuration":true,"didChangeConfiguration":{"dynamicRegistration":true}},"textDocument":{"completion":{"completionItem":{"snippetSupport":false}},"hover":{"contentFormat":["plaintext"]}}},"processId":1874,"workspaceFolders":[{"uri":"file:///home/ubuntu/mesa/go/src/foo","name":"/home/ubuntu/mesa/go/src/foo"}]}}
{"id":1,"jsonrpc":"2.0","result":null}
{"jsonrpc":"2.0","method":"client/registerCapability","params":{"registrations":[{"id":"workspace/didChangeConfiguration","method":"workspace/didChangeConfiguration"},{"id":"workspace/didChangeWorkspaceFolders","method":"workspace/didChangeWorkspaceFolders"}]},"id":1}
stderr: 2020/02/11 06:04:50 debug server listening on port 41593
{"method":"textDocument/didOpen","jsonrpc":"2.0","params":{"textDocument":{"uri":"file:///home/ubuntu/mesa/go/src/foo/fileb.go","version":1,"languageId":"go","text":"package foo\n\nimport (\n\t\"fmt\"\n)\n\ntype Bar struct {\n\ta int\n}\n\nfunc DoSomething(f *Foo, b *Bar) {\n\t// ctrl+] in Bar works (inside this file), Foo does not (inside the package, but not this file)\n\tfmt.Println(\"\") // Println works (outside this package)\n}\n"}}}
{"method":"initialized","jsonrpc":"2.0","params":{}}
{"jsonrpc":"2.0","result":{"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"completionProvider":{"triggerCharacters":["."]},"hoverProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"codeActionProvider":true,"codeLensProvider":{},"documentLinkProvider":{},"documentFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"renameProvider":true,"foldingRangeProvider":true,"executeCommandProvider":{"commands":["tidy"]},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":"workspace/didChangeWorkspaceFolders"}}},"serverInfo":{"name":""}},"id":1}
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2020/02/11 06:04:50 Build info\n----------\ngolang.org/x/tools/gopls v0.3.1\n    golang.org/x/tools/gopls@v0.3.1 h1:yNTWrf4gc4Or0UecjOas5pzOa3BL0WDDyKDV4Wz5VaM=\n    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\n    github.com/sergi/go-diff@v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=\n    golang.org/x/mod@v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=\n    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=\n    golang.org/x/tools@v0.0.0-20200204151227-34c67990bfe7 h1:hWZVyLW37WdETuLIGQMvQIhMfXXAOANmAIEAluZMy3c=\n    golang.org/x/xerrors@v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=\n    honnef.co/go/tools@v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=\n    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=\n\nGo info\n-------\ngo version go1.13.3 linux/amd64\n\nGO111MODULE=\"\"\nGOARCH=\"amd64\"\nGOBIN=\"\"\nGOCACHE=\"/home/ubuntu/.cache/go-build\"\nGOENV=\"/home/ubuntu/.config/go/env\"\nGOEXE=\"\"\nGOFLAGS=\"\"\nGOHOSTARCH=\"amd64\"\nGOHOSTOS=\"linux\"\nGONOPROXY=\"\"\nGONOSUMDB=\"\"\nGOOS=\"linux\"\nGOPATH=\"/home/ubuntu/mesa/go\"\nGOPRIVATE=\"\"\nGOPROXY=\"https://proxy.golang.org,direct\"\nGOROOT=\"/usr/src/go1.13.3/go\"\nGOSUMDB=\"sum.golang.org\"\nGOTMPDIR=\"\"\nGOTOOLDIR=\"/usr/src/go1.13.3/go/pkg/tool/linux_amd64\"\nGCCGO=\"gccgo\"\nAR=\"ar\"\nCC=\"gcc\"\nCXX=\"g++\"\nCGO_ENABLED=\"1\"\nGOMOD=\"\"\nCGO_CFLAGS=\"-g -O2\"\nCGO_CPPFLAGS=\"\"\nCGO_CXXFLAGS=\"-g -O2\"\nCGO_FFLAGS=\"-g -O2\"\nCGO_LDFLAGS=\"-g -O2\"\nPKG_CONFIG=\"pkg-config\"\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build590064323=/tmp/go-build -gno-record-gcc-switches\"\n"}}
{"id":2,"jsonrpc":"2.0","result":[{"buildFlags":[],"hoverKind":"NoDocumentation"},{"buildFlags":[],"hoverKind":"NoDocumentation"}]}
{"jsonrpc":"2.0","method":"workspace/configuration","params":{"items":[{"scopeUri":"file:///home/ubuntu/mesa/go/src/foo","section":"gopls"},{"scopeUri":"file:///home/ubuntu/mesa/go/src/foo","section":"gopls-/home/ubuntu/mesa/go/src/foo"}]},"id":2}
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":1,"message":"2020/02/11 06:04:50 initial workspace load failed: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./... builtin]: exit status 1: go build foo: failed to cache compiled Go files\n"}}
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2020/02/11 06:04:50 go/packages.Load\n\tsnapshot = 0\n\tquery = [./... builtin]\n\tpackages = 0"}}
stderr: 
stderr: 2020/02/11 06:04:50 initial workspace load failed: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./... builtin]: exit status 1: go build foo: failed to cache compiled Go files
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2020/02/11 06:04:50 go/packages.Load\n\tsnapshot = 1\n\tpackage = command-line-arguments\n\tfiles = [/home/ubuntu/mesa/go/src/foo/fileb.go]"}}
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"2020/02/11 06:04:50 go/packages.Load\n\tsnapshot = 1\n\tquery = [file=/home/ubuntu/mesa/go/src/foo/fileb.go]\n\tpackages = 1"}}
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///home/ubuntu/mesa/go/src/foo/fileb.go","version":1,"diagnostics":[{"range":{"start":{"line":10,"character":20},"end":{"line":10,"character":23}},"severity":1,"source":"compiler","message":"undeclared name: Foo"}]}}

@bhcleek
Copy link
Collaborator

bhcleek commented Feb 11, 2020

It looks like the problem here is gopls, but I'm not sure what would cause the error it's reporting. @stamblerre can you provide any guidance?

@PaulForgey what version of vim-go are you using? If you're on v1.22, you can run :GoUpdateBinaries gopls to install gopls v0.2.2

@PaulForgey
Copy link
Author

The only binary involved here outside of the go toolchain is gopls.

I suspect an intermediate outside module used in the building the binary has perhaps updated. It's the only way I can explain taking a previously working installation and breaking it by simply re-building the binaries clean.

@PaulForgey
Copy link
Author

PaulForgey commented Feb 11, 2020

I'm on v1.22 (also tried master), I already did GoUpdateBinaries gopls so I am actually on.. v0.3.1?? Let me try that again from v1.22..

that puts me on v0.3.1

@PaulForgey
Copy link
Author

in the meantime, setting go_def_mode to godef lets me get on with my workday..

@bhcleek
Copy link
Collaborator

bhcleek commented Feb 11, 2020

@PaulForgey Does :GoBuild succeed when run in your fileb.go file?

@PaulForgey
Copy link
Author

@bhcleek yes

@PaulForgey
Copy link
Author

While I am consistently reproducing this on both Linux (4.9.37) and MacOS (Darwin 18.7.0) with the same version of vim in this report, go_def_mode set to 'godef' does have random wrong behavior as well, which sometimes changes after either :e or :w, flapping between not seeing symbols outside the file, navigating to the wrong file entirely, or working.

@bhcleek
Copy link
Collaborator

bhcleek commented Feb 15, 2020

I'm not able to replicate any of the problems described here. If you can provide a complete set of steps to replicate this on a clean system, I'm happy to investigate more.

@stamblerre
Copy link
Contributor

Sorry for not replying here earlier. In the gopls log above, there seems to be a go list error that is preventing gopls from loading the workspace:

initial workspace load failed: go [-e -json -compiled=true -test=true -export=false -deps=true -find=false -- ./... builtin]: exit status 1: go build foo: failed to cache compiled Go files

@PaulForgey: Do you consistently see this error?

/cc @jayconrod for go list advice - should we try to recover from this error by re-running go list?

@jayconrod
Copy link

If you can reproduce the error go build foo: failed to cache compiled Go files, please open a new issue on https://github.com/golang/go with details. golang/go#29667 is related, but that was fixed in 1.13. In that issue, we were having some trouble with concurrent access to the build cache by multiple tools.

@stamblerre Retrying go list is a good workaround. Would love to fix the root cause though if we can isolate it.

@PaulForgey
Copy link
Author

@stamblerre I do constantly see that and missed it myself. After cleaning again and this time making sure no oddly owned/perm’d files were left behind, I am no longer consistently seeing this.

@PaulForgey
Copy link
Author

:go build never fails, but I do go build from the command line with editors open all the time, and so perhaps I could be tripping on some cache concurrency issues.

@stamblerre
Copy link
Contributor

@PaulForgey: Glad things are working again. If you run into this again, please do report an issue on the Go repository.

@bhcleek
Copy link
Collaborator

bhcleek commented Feb 18, 2020

@PaulForgey should we close this?

@PaulForgey
Copy link
Author

yes, thank you.

@bhcleek bhcleek closed this as completed Feb 18, 2020
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

4 participants