bazel-contrib / bazel-contrib/rules_go

VSCode support for Bazel + Go project doesn't work correctly for new packages

Open
#3,014 12 comments 5 reactions 1 assignee Claimed by @steeve View on GitHub
IDE tools
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

### What version of rules_go are you using?
v0.29.0

### What version of gazelle are you using?
v0.24.0

### What version of Bazel are you using?
4.2.1

### Does this issue reproduce with the latest releases of all the above?
I am using the latest versions already.

### What operating system and processor architecture are you using?
Intel Mac

### Any other potentially useful information about your toolchain?

Here's my `.vscode/settings.json` file:
```
{
"go.goroot": "${workspaceFolder}/bazel-myrepo/external/go_sdk",
"go.toolsEnvVars": {
"GOPACKAGESDRIVER": "${workspaceFolder}/tools/editor/gopackagesdriver.sh"
},
"gopls": {
"formatting.local": "example.com"
}
}
```
Here's my `tools/editor/gopackagesdriver.sh` file:
```
#!/bin/bash

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

### What's working

We have a Go repo that's using Bazel. I am trying to make changes to that repo from VSCode. With the above mentioned files in the repo, "Go to Definition" etc. started working. Thank you! :)

### What's not working

However, when I add a new package (along with its `BUILD.bazel` file), I can't successfully import it from another package (even after adding the new package in the `deps` of the `go_library` rule).

The import shows a red squiggly line which says the following on hover:
```
could not import example.com/nodeinit/newpkg (cannot find package "example.com/nodeinit/newpkg" in any of
/Users/rohit_agarwal/repos/myrepo/bazel-myrepo/external/go_sdk/src/example.com/nodeinit/newpkg (from $GOROOT)
/Users/rohit_agarwal/go/src/example.com/nodeinit/newpkg (from $GOPATH)) compiler(BrokenImport)
```

If I restart VSCode, the error goes away.

IntelliJ IDEA (GoLand) also has a similar issue with new packages, however there the problem is fixed by `Sync Project with BUILD Files` without restarting the IDE.

---

cc @steeve @linzhp

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.