rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

gopackagesdriver + gopls is leading to "warning: diagnostics failed: stat [filepath] no such file or directory"

Open tenzinhl opened this issue 1 year ago • 2 comments

I'm using gopackagesdriver with gopls in VSCode for a Go project built with Bazel. Followed the rules_go Editor Setup for VSCode 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. 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:

{
    "[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,
    },
}

tenzinhl avatar Feb 05 '25 21:02 tenzinhl

I don't have a solution, just was looking around for related issues - I think we have the same issue: https://github.com/bazel-contrib/rules_go/issues/4286.

Interestingly in my case I have one development machine that works, and one that does not.

kylepl avatar Mar 01 '25 15:03 kylepl

While I'm not sure how it works, or if it will work long-term, I have a work-around at least for me in https://github.com/bazel-contrib/rules_go/issues/4286#issuecomment-2692334131.

kylepl avatar Mar 01 '25 17:03 kylepl