I am using the LSP-gopls plugin. When I write Go code, I have this message on the LSP Diagnostics Panel
4:2 error could not import myProject (cannot find package "myProject" in any of compiler:
/usr/local/Cellar/go/1.17.2/libexec/src/dst (from $GOROOT)
/Users/username/go/src/myProject (from $GOPATH))
I notice it’s using the system default GOROOT and GOPATH, which I have override with my own setup using gvm
. So if I type which go
in the terminal, I have
$ which go
/Users/username/.gvm/gos/go1.16.7/bin/go
I tried to configure this in the LSP setting by adding the env
field
// Settings in here override those in "LSP/LSP.sublime-settings"
{
"clients": {
"gopls": {
"env": {
"PATH": "/Users/username/.gvm/gos/go1.16.7",
"GOPATH": "/Users/username/.gvm/pkgsets/go1.16.7/global"
},
"enabled": true,
"command": ["gopls"],
"selector": "source.go",
"initializationOptions": {
"experimentalWorkspaceModule": false
}
}
}
}
However, the message still exists. I have also tried
- restart the LSP server using
LSP: Restart Server
- and restart the Sublime Text itself.
I am pretty sure the error message wasn’t correct, because the code runs fine, and running the gopls check
command gives no error in the terminal.
Spec
I am using
- MacOS Monterey(12.0.1)
- Sublime Text 4 (Build 4121)
- LSP v1.14.0
- LSP-gopls V1.0.2
Any suggestions?