bazel-contrib / bazel-contrib/rules_go
gopackagesdriver + gopls is leading to "warning: diagnostics failed: stat [filepath] no such file or directory"
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 760
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 12
Description
I'm using `gopackagesdriver` with `gopls` in VSCode for a Go project built with Bazel. Followed the [`rules_go` Editor Setup for VSCode](https://github.com/bazel-contrib/rules_go/wiki/Editor-setup#visual-studio-code) to get VSCode intellisense. It worked when I first set it up yesterday, however today it started failing.
It seems like `gopackagesdriver` is telling `gopls` to reference a nonexistent path. Checking the `gopls (server)` output shows messages like:
```
[Error - 9:12:06 PM] 2025/02/05 21:12:06 warning: diagnostics failed: stat /home/user/.cache/bazel/_bazel_user/b35369edf9c0f7898c0f9d8e0d24f857/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_go~/stdlib_/gocache/c6/c689520eead32197b36815d0861427bae887a9d3ff84e35d3e6528696e32b7f1-d: no such file or directory
view_id="1"
snapshot=1
directory=/home/user/repos/company
```
There's a bunch more of these errors, and they all complain about not finding this `c689520eead32197b36815d0861427bae887a9d3ff84e35d3e6528696e32b7f1-d` file. I see that everything up until `gocache` exists on my filesystem. It's just that the cache is empty:
```
user@dev-user0 ~/./b/_/b/e/_/b/k/b/e/r/stdlib_> pwd
/home/user/.cache/bazel/_bazel_user/b35369edf9c0f7898c0f9d8e0d24f857/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_go~/stdlib_
user@dev-user0 ~/./b/_/b/e/_/b/k/b/e/r/stdlib_> ls -lah gocache
total 8.0K
dr-xr-xr-x 2 user user 4.0K Feb 5 21:04 .
drwxr-xr-x 4 user user 4.0K Feb 5 21:04 ..
```
Full `gopls` server log (as pulled from the VSCode output tab): [gopls-log.txt](https://github.com/user-attachments/files/18679173/gopls-log.txt). I've run `bazel clean --expunge` and restarted the `gopls` language server to have a "clean" environment before producing this log.
With this no intellisense works in VSCode. All `gopls` functions error out.
## Environment
`rules_go` version 0.51:
```
bazel_dep(name = "rules_go", version = "0.51.0", repo_name = "io_bazel_rules_go")
```
`./tools/gopackagesdriver.sh` (we import the `rules_go` repo as `io_bazel_rules_go`):
```
#!/usr/bin/env bash
exec bazel run -- @io_bazel_rules_go//go/tools/gopackagesdriver "${@}"
```
`.vscode/settings.json`:
```json
{
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
},
"python.analysis.extraPaths": [
"research/gpt-neox"
],
"python.analysis.include": [
"base",
"clients",
"experimental",
"models",
"research",
"services",
"third_party",
"tools"
],
"python.analysis.exclude": [
"base/datasets/stubs",
"**/.bazel_output/**",
"**/node_modules/**", // we do get python code in node_modules!
],
"python.analysis.typeCheckingMode": "standard",
"rust-analyzer.linkedProjects": [
"./Cargo.toml",
],
"jsonnet.languageServer.formatting": {
"Indent": 2
},
// Settings for go/bazel are based on editor setup instructions at
// https://github.com/bazelbuild/rules_go/wiki/Editor-setup#visual-studio-code
"go.goroot": "${workspaceFolder}/bazel-${workspaceFolderBasename}/external/rules_go~~go_sdk~main___download_0/",
"go.toolsEnvVars": {
"GOPACKAGESDRIVER": "${workspaceFolder}/tools/gopackagesdriver.sh"
},
"go.enableCodeLens": {
"runtest": false
},
"gopls": {
"build.directoryFilters": [
"-bazel-bin",
"-bazel-out",
"-bazel-testlogs",
"-bazel-company"
],
"formatting.gofumpt": true,
"formatting.local": "github.com/companycode/company",
"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
},
},
"go.useLanguageServer": true,
"go.buildOnSave": "off",
"go.lintOnSave": "off",
"go.vetOnSave": "off",
"files.exclude": {
"**/__pycache__": true,
"**/.pytest_cache": true,
"**/*.egg-info": true,
"**/node_modules": true,
"**/bazel-company": true,
"**/bazel-bin": true,
"**/bazel-out": true,
"**/bazel-testlogs": true,
"**/.bazel_output": true,
},
}
```
Contributor guide
Research direction
Start with tools/gopackagesdriver.sh, the rules_go VSCode editor setup, and the attached gopls-log.txt. Reproduce the empty gocache path using the reported rules_go 0.51 environment, then trace the package paths returned to gopls. Done means gopls no longer reports missing files and VSCode IntelliSense functions work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, go, vscode
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100