-
-
Notifications
You must be signed in to change notification settings - Fork 723
Editor setup
Jay Conrod edited this page Jul 7, 2021
·
21 revisions
The packages driver fundamentally works from the perspective of one or more targets. In order for it to function properly, the targets must be specified in the packages driver configuration, with environment variables.
These are:
-
GOPACKAGESDRIVER_BAZEL_TARGETS: specifies specific targets,//...works too (although this is not recommended without tag filters). It is possible to set targets to something other thango_rules, as long as thego_nodes are reachable via thedepsattribute in the graph. Such as whengo_binary(linkmode = "c-archive") -> cc_library. -
GOPACKAGESDRIVER_BAZEL_QUERY: runs abazel queryto select targets before, common one should bekind(go_binary, //...). This should work for most cases. -
GOPACKAGESDRIVER_BAZEL_TAG_FILTERS: makes use of the--build_tag_filtersoption to only build (filter) targets with certain tags. This is useful for when you want each target to define wether or not it should be part of the packages list. For instance, setGOPACKAGESDRIVER_BAZEL_TARGETS="//..."andGOPACKAGESDRIVER_BAZEL_TAG_FILTERS="completion"to only build targets with thecompletiontag in the whole workspace.
In addition, those environment variables are optional:
-
GOPACKAGESDRIVER_BAZEL: bazel binary, defaults tobazel -
BUILD_WORKSPACE_DIRECTORY: directory of the bazel workspace (should be auto detected when using a launcher script because it invokesbazel run)
You'll need gopls >= v0.6.10 (released on Apr 13th 2021). If you are using VSCode, it should be automatic.
Create a launcher script, say tools/gopackagesdriver.sh:
#!/usr/bin/env bash
exec bazel run -- @io_bazel_rules_go//go/tools/gopackagesdriver "${@}"In .vscode/settings.json add the following:
"go.goroot": "${workspaceFolder}/bazel-${workspaceFolderBasename}/external/go_sdk",
"go.toolsEnvVars": {
"GOPACKAGESDRIVER_BAZEL_QUERY": "kind(go_binary, //...)",
"GOPACKAGESDRIVER": "${workspaceFolder}/tools/gopackagesdriver.sh"
},
"go.useLanguageServer": true,Open VSCode, and after a while the packages should be properly detected after the build is done.
The same principles should apply for vim-go or any editor that uses gopls.
- CGo completion may not work, but at least it's not explicitly supported.
- Errors are not handled
-
Query patterns are ignored and the whole graph is returned each timepatterns are now used -
Root packages detection is probably wrongit should be better now