Description
gopls version
(version: v0.17.0 built with go: go1.23.4)
go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/wanjia-he/.cache/go-build'
GOENV='/home/wanjia-he/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/wanjia-he/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/wanjia-he/go'
GOPRIVATE=''
GOPROXY='https://goproxy.woa.com,direct'
GOROOT='/home/wanjia-he/.cache/bazel/_bazel_wanjia-he/c3e05d378a37a82e15a3115ca8042150/external/go_sdk'
GOSUMDB='sum.woa.com+643d7a06+Ac5f5VOC4N8NUXdmhbm8pZSXIWfhek5JSmWdWrq7pLX4'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/wanjia-he/.cache/bazel/_bazel_wanjia-he/c3e05d378a37a82e15a3115ca8042150/external/go_sdk/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.0'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/wanjia-he/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build971942491=/tmp/go-build -gno-record-gcc-switches'
What did you do?
Our project uses bazel with a monorepo setup, I am using vscode and trying to get gopls working with my golang projects. The OS I am running is ubuntu 24.04.
My vscode settings looks like this:
"go.goroot": "${workspaceFolder}/bazel-${workspaceFolderBasename}/external/go_sdk",
"go.toolsEnvVars": {
"GOPACKAGESDRIVER": "${workspaceFolder}/scripts/gopackagesdriver.sh",
"GOPACKAGESDRIVER_BAZEL_BUILD_FLAGS": "--strategy=GoStdlibList=local",
},
"go.enableCodeLens": {
"runtest": false
},
"gopls": {
"build.directoryFilters": [
"-bazel-bin",
"-bazel-out",
"-bazel-testlogs",
"-bazel-robotics",
],
"formatting.gofumpt": true,
"formatting.local": "data_pipeline",
"ui.completion.usePlaceholders": true,
"ui.semanticTokens": true,
"ui.codelenses": {
"gc_details": false,
"regenerate_cgo": false,
"generate": false,
"test": false,
"tidy": false,
"upgrade_dependency": false,
"vendor": false
},
"verboseOutput": true
},
"go.useLanguageServer": true,
"go.lintOnSave": "off",
"go.vetOnSave": "off",
"go.languageServerFlags": [
"-rpc.trace"
]
Here is my sample golang code:
package main
import "fmt"
func main() {
fmt.Println("this is an agent in go")
}
What did you see happen?
So compling is fine with the project, the external packages (including the pb.go packages generated from .proto files with bazel) is working well, I can use F12 to go to the definitions, use autofills etc. However, the standard libraries are broken, e.g. fmt, http.
The source code of "fmt" package is there under ***/go_sdk/src directory.
When I hover the mouse on "fmt", it shows error:
could not import fmt (missing metadata for import of "fmt")compilerBrokenImport
If I press F12, it says:
No definition found for "fmt"
What did you expect to see?
When I hover on "fmt" and press F12, vscode should take me to the source code of "fmt".
When I call fmt.***, autofill should work.
Editor and settings
No response
Logs
[Trace - 20:44:31.202 PM] Sending request 'textDocument/hover - (118)'.
Params: {"textDocument":{"uri":"file:///home/wanjia-he/Documents/robotics/data_pipeline/upload_agent_go/main.go"},"position":{"line":2,"character":11}}
[Error - Received] 20:44:31.202 PM #118 no package data for import "fmt"
[Error - 12:44:31 PM] Request textDocument/hover failed.
Message: no package data for import "fmt"
Code: 0
[Trace - 20:44:31.385 PM] Sending request 'textDocument/hover - (119)'.
Params: {"textDocument":{"uri":"file:///home/wanjia-he/Documents/robotics/data_pipeline/upload_agent_go/main.go"},"position":{"line":2,"character":10}}
[Error - Received] 20:44:31.385 PM #119 no package data for import "fmt"
[Error - 12:44:31 PM] Request textDocument/hover failed.
Message: no package data for import "fmt"
Code: 0
[Trace - 20:44:31.543 PM] Sending request 'textDocument/codeAction - (120)'.
Params: {"textDocument":{"uri":"file:///home/wanjia-he/Documents/robotics/data_pipeline/upload_agent_go/main.go"},"range":{"start":{"line":2,"character":7},"end":{"line":2,"character":12}},"context":{"diagnostics":[{"range":{"start":{"line":2,"character":7},"end":{"line":2,"character":12}},"message":"could not import fmt (missing metadata for import of "fmt")","code":"BrokenImport","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#BrokenImport"},"severity":1,"source":"compiler"}],"only":["quickfix"],"triggerKind":1}}
[Trace - 20:44:31.544 PM] Received response 'textDocument/codeAction - (120)' in 0ms.
Result: null
[Trace - 20:44:31.544 PM] Received notification 'window/logMessage'.
Params: {"type":3,"message":"2024/12/19 20:44:31 fixImports(filename="/home/wanjia-he/Documents/robotics/data_pipeline/upload_agent_go/main.go"), srcDir="/home/wanjia-he/Documents/robotics/data_pipeline/upload_agent_go/main.go" ...%!(EXTRA string=/home/wanjia-he/Documents/robotics/data_pipeline/upload_agent_go)\n"}
[Info - 12:44:31 PM] 2024/12/19 20:44:31 fixImports(filename="/home/wanjia-he/Documents/robotics/data_pipeline/upload_agent_go/main.go"), srcDir="/home/wanjia-he/Documents/robotics/data_pipeline/upload_agent_go/main.go" ...%!(EXTRA string=/home/wanjia-he/Documents/robotics/data_pipeline/upload_agent_go)