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

rules_go 0.40+ broke gopls resolving stdlib imports in VS code #3741

Open
bluec0re opened this issue Oct 30, 2023 · 4 comments
Open

rules_go 0.40+ broke gopls resolving stdlib imports in VS code #3741

bluec0re opened this issue Oct 30, 2023 · 4 comments

Comments

@bluec0re
Copy link

bluec0re commented Oct 30, 2023

What version of rules_go are you using?

Tested with 0.40.1 and 0.42

What version of gazelle are you using?

0.31.1 and 0.33

What version of Bazel are you using?

6.4.0

Does this issue reproduce with the latest releases of all the above?

Yes

What operating system and processor architecture are you using?

Linux amd64

Any other potentially useful information about your toolchain?

Tested with gopls 0.13.2 and 0.14.1.

Using these settings in VS code:

 "go.goroot": "${workspaceFolder}/bazel-${workspaceFolderBasename}/external/go_sdk/",
  "go.toolsEnvVars": {
    "GOPROXY": "off",
    "GOPACKAGESDRIVER": "${workspaceFolder}/scripts/gopackagesdriver.sh",
  },
  "gopls": {
    "build.directoryFilters": [
      "-bazel-bin",
      "-bazel-out",
      "-bazel-testlogs",
      "-bazel-${workspaceFolderBasename}"
    ],
    [...]
  },

and this gopackagesdriver.sh:

#!/bin/sh

bazel="$(command -v bazel || command -v bazelisk)"
# reset GOPROXY to default
unset GOPROXY

# don't fetch internal stuff
export GOPRIVATE="[...]*"

exec "${bazel}" run -- @io_bazel_rules_go//go/tools/gopackagesdriver "$@"

What did you do?

Updated rules_go from 0.39.1 to 0.42 (and then later backtracked the problem to 0.40)

What did you expect to see?

gopls is able to resolve stdlib imports in VS code as before.

What did you see instead?

A lot of import errors in the format of could not import $PKG (cannot find packge "$PKG" in GOROOT or GOPATH).

@JamyDev
Copy link
Contributor

JamyDev commented Dec 7, 2023

Could you provide the output of echo {} | ./scripts/gopackagesdriver.sh builtin and save it on gist.github.com?

@bluec0re
Copy link
Author

bluec0re commented Dec 8, 2023

I saved the output for 0.39.1 and 0.40.1 and also a diff between them.

To be able to generate the diff, it used echo {} | ./scripts/gopackagesdriver.sh builtin | jq '.Packages |= sort_by(.PkgPath)' | jq '.Roots |= sort' to create the files.

@bluec0re
Copy link
Author

bluec0re commented Dec 8, 2023

Interestingly, it shows no error for unsafe but the gopls logs report "no readable files" when using jump to definition:

image

[Error - 12:38:35 PM] Request textDocument/definition failed.
  Message: package "@io_bazel_rules_go//stdlib:unsafe" has no readable files
  Code: 0 

@JamyDev
Copy link
Contributor

JamyDev commented Dec 8, 2023

Do you know what gopls version you're running? the outputs you shared seem normal 🤔

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

2 participants