go/packages.Load: no packages found
2019-10-22
Categories: Programming
I have a mono-repo, structure like this:
1repo 2├── service1 3├── service2 4├── go.mod
I often open the root folder from the command line by using code .. After that I open a file in service1, and cannot go to definition. Here’s the logs from gopls:
1[Info - 5:49:28 AM] 2019/10/22 05:49:28 20.675656ms for GOROOT=/usr/local/Cellar/go/1.13/libexec GOPATH=/Users/quanta/go GO111MODULE=auto PWD=/Users/quanta/go/src/github.com/owner/repo go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/quanta/go/src/github.com/owner/repo/a/b/c", stderr: <<go: directory a/b/c is outside main module 2>> 3 4[Error - 5:49:32 AM] Request textDocument/definition failed. 5 Message: go/packages.Load: no packages found for /Users/quanta/go/src/github.com/owner/repo/a/b/c/file.go 6 Code: 0
- https://github.com/golang/go/issues/32667
- https://github.com/golang/go/issues/32394
- https://github.com/microsoft/vscode-go/issues/2490
So, gopls only works if we open vscode at the module root (service1, service2 in this case). If you open vscode at the project root, you have to use File -> Add Folder to Workspace to create a workspace with multiple folders.
Related Posts:
- launchctl: Bootstrap failed: 5: Input/output error
- Integration testing TUI applications in Rust
- libp2p performance benchmarking
- Learning Rust by building Tetris: my favorite childhood game
- SICP Exercise 2.77: expected a procedure that can be applied to arguments, given #f
Quan Tong