I am using Go 1.19 and VSCode 1.70.2 on Mac. My problem is that when I right click on a function name and choose "Go to Definition" or "Fn F12" it says "No definition found " I have gopls installed and here is the snippet for gopls
"go.useLanguageServer": true,
"gopls": {
"usePlaceholders": true, // add parameter placeholders when completing a function
"completionDocumentation": true // for documentation in completion items
},
I have restarted the VSCode after adding the above modifications. I have tried other related functions like "ctrl + click" or control + hover etc, and they also do not work.
Note: The code compiles and runs. However, Visual Code shows an error:
Error loading workspace: err: exit status 1: stderr: package unsafe is not in GOROOT
There is no reference to package "unsafe" in this workspace at all. I do use package unsafe in some other workspace.
Here is what I see in the Output window:
[Info - 1:13:53 PM] 2022/08/21 13:13:53 go env for /Users/path-to-project
(root /Users/path-to-project)
(go version go version go1.19 darwin/arm64)
(valid build configuration = false)
(build flags: [])
GOWORK=
GONOPROXY=
GOPROXY=https://proxy.golang.org,direct
GO111MODULE=
GOINSECURE=
GOSUMDB=sum.golang.org
GOMOD=/dev/null
GOPRIVATE=
GOMODCACHE=/Users/username/go/pkg/mod
GOFLAGS=
GOPATH=/Users/username/go
GOROOT=/Users/username/go/pkg/mod
GOCACHE=/Users/username/Library/Caches/go-build
GONOSUMDB=
[Info - 1:13:53 PM] 2022/08/21 13:13:53 7.916792ms for GOROOT=/Users/jusername/go/pkg/mod GOPATH=/Users/username/go GO111MODULE=auto GOPROXY=https://proxy.golang.org,direct PWD=/Users/jpath-to-project go list -f "{{context.GOARCH}} {{context.Compiler}}" -- unsafe
[Info - 1:13:53 PM] 2022/08/21 13:13:53 6.871ms for GOROOT=/Users/username/go/pkg/mod GOPATH=/Users/username/go GO111MODULE=off GOPROXY=https://proxy.golang.org,direct PWD=/Users/path-to-project go list -e -f {{context.ReleaseTags}} -- unsafe
[Info - 1:13:53 PM] 2022/08/21 13:13:53 9.467042ms for GOROOT=/Users/username/go/pkg/mod GOPATH=/Users/username/go GO111MODULE=auto GOPROXY=https://proxy.golang.org,direct PWD=/Users/path-to-project go list -e -json=Name,ImportPath,Error,Dir,GoFiles,IgnoredGoFiles,IgnoredOtherFiles,CFiles,CgoFiles,CXXFiles,MFiles,HFiles,FFiles,SFiles,SwigFiles,SwigCXXFiles,SysoFiles,TestGoFiles,XTestGoFiles,CompiledGoFiles,Export,DepOnly,Imports,ImportMap,TestImports,XTestImports,ForTest,DepsErrors,Module -compiled=true -test=true -export=false -deps=true -find=false -- ./ builtin
[Error - 1:13:53 PM] 2022/08/21 13:13:53 go/packages.Load #1: err: exit status 1: stderr: cannot find package "unsafe" in any of:
/Users/username/go/pkg/mod/src/unsafe (from $GOROOT)
/Users/username/go/src/unsafe (from $GOPATH)
snapshot=0
directory=/Users/path-to-project
query=[./ builtin]
packages=0
[Error - 1:13:53 PM] 2022/08/21 13:13:53 initial workspace load failed: err: exit status 1: stderr: cannot find package "unsafe" in any of:
/Users/username/go/pkg/mod/src/unsafe (from $GOROOT)
/Users/username/go/src/unsafe (from $GOPATH)
: packages.Load error
[Error - 1:13:53 PM] 2022/08/21 13:13:53 errors loading workspace: err: exit status 1: stderr: cannot find package "unsafe" in any of:
/Users/username/go/pkg/mod/src/unsafe (from $GOROOT)
/Users/username/go/src/unsafe (from $GOPATH)
: packages.Load error
snapshot=0
directory=file:///Users/path-to-project
[Info - 1:13:53 PM] 2022/08/21 13:13:53 fixImports(filename="/Users/usedrname/path-to-project/somefile.go), abs="/Users/path-to-project/somefile.go”, srcDir="/Users/path-to-project" ...
[Error - 1:13:53 PM] Request textDocument/codeAction failed.
Message: err: exit status 1: stderr: cannot find package "unsafe" in any of:
/Users/username/go/pkg/mod/src/unsafe (from $GOROOT)
/Users/username/go/src/unsafe (from $GOPATH)
: packages.Load error
Code: 0