Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tenzinhl opened this issue Feb 5, 2025 · 0 comments

Comments

@tenzinhl
Copy link

tenzinhl commented Feb 5, 2025

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,
    },
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant