Description
I'm trying to get golsp to work with vim through https://github.com/autozimu/LanguageClient-neovim.
Golsp seems to work very well for me when editing Go source code in GOPATH. However, when editing Go source inside a module, golsp reports
"no packages found for </path/to/gofile.go>"
when I attempt the "go to definition" command.
My project structure resembles this template:
project/
.git/
src/
example.com/
go.mod
source.go
It seems that the problem is a mismatch between the language server "project path" and the go module path.
The project path is sent through the "initialize" lsp request in the "rootPath" and "rootUri" fields by LanguageClient-neovim. LanguageClient-neovim also starts the golsp executable with the project path as its current directory. Its unclear exactly how the project path is determined, but it seems to be the root of the git project containing the Go source file I'm editing. In my case, "project/".
Now, when golsp attempts to determine the packages containing for the open Go source file it fails because
pkgs, err := packages.Load(v.Config, fmt.Sprintf("file=%s", path))
fails to find the current module in golsp's current working directory, "project/".
To test my hypothesis, I added
Dir: "</path/to/project/src/example.com>"
to the packages.Config used above and sure enough, "go to definition" and other lsp features started working again.
I'm sorry if this is a known issue. If so, I hope this issue can be a placeholder for resolving it.
CC @stamblerre.