Bazel Support for Visual Studio Code.
This extension provides editor support for the starlark language and the bazel
dialect of starlark.
The following operating systems are supported:
NOTE: while the list above is sorted alphabetically, windows is not an
afterthought; one of the main supporters of bazel-stack-vscode is a
The major contribution points include:
starlark language (matches
bazel language (matches
.bzl and related files).
bazelrc language (matches
.bazelrc and related files).
starlark grammar (syntax highlighting for
bazel grammar (syntax highlighting for
bazelrc grammar (syntax highlighting for
See Keybindings for description of commands bound to keyboard
shortcuts. Other commands included are typically meant to be activated by menus
or buttons (see Tools).
shift+cmd+space runs the
bsv.bzl.redo command; to use this, click on a
build/test code action to run it the first time; then slap the space bar
while holding down the command key to quickly rebuild/retest it.
ctrl+shift+cmd+b runs the
bsv.bzl.copyLabel command. To use this, place
your cursor in the
name of a build rule (e.g.
name = "my_f|oo_library")
and stroke the keybinding; the full label
//pkg/app:my_foo_library will be
copied to the clipboard.
cmd+; runs the
bsv.bzl.goToLabel command. To use this, stroke the
keybinding (designed to be ergonomically similar to the builtin
this will open an input box where you can type/paste in a bazel label; press
ENTER to move to the rule/file implied by the label.
shift+cmd+t runs the
workbench.view.extension.bazel-explorer command. This
will show the Tools.
ctrl+shift+cmd+p runs the
bsv.buildozer.wizard command. To use this,
stroke the keybinding; a sequence of input boxes / picks will guide you
through formulating a buildozer command.
bazel-explorer contains a number of so-called Tools. Each tool has
a similar look-and-feel for enablement, configuration, documentation/help, and
possible launch/execution of the tool. See Tools for reference.
- Support for
bazel language debugging via the debug adapter protocol. See
description of the Starlark Debugger Tool for
- Support for setting breakpoints for the
bazel language. See
bazel language snippets for templating out rule, provider
The activity view contains a list of tree items; each top-level item
represents a "tool". The tool may be something like
actually downloads and runs an executable; or something like a service that
shows information (e.g.
Each "tool" component has a set of configurable elements; to configure them
either expand the Settings tree item and click on it, or go directly to your
user/workspace settings and hunt for the corresponding configuration item (e.g.
Buildifier provides linting and formatting support for the
bazel language. It
is highly recommended to always format on save: to do this, add the following to
Buildozer performs bulk editing of BUILD files and can be very useful for
various refactoring activities. If you are buildozer expert, you may not need
this. For the rest of us who use buildozer relatively infrequently, you can use
bsv.buildozer.wizard to help step through the various possibilities and
construct a buildozer command. See Keybindings.
The starlark debugger tool launches the debug adapter tool when a
language debug session is starting. You can customize the settings used for the
adapter or the bazel server.
See the Debugging
section of the docs for more details.
The starlark language server provides LSP support for the
languages. Supported features include:
- code actions: code action links for
[LABEL]: clicking on this code action will copy the label to the clipboard.
build: clicking on this code action will run
bazel build [LABEL] in an
test: clicking on this code action will run
bazel test [LABEL] in an
run: clicking on this code action will run
bazel run [LABEL] in an
debug: clicking on this code action will run
bazel build [LABEL] --experimental_skylark_debug and start a starlark debugging session.
codesearch: clicking on this code action will show the Codesearch
UI for that label. This allows you to "livegrep"
withing the transitive set of source files required to build
ui: clicking on this code action will open an external link to the
[LABEL] in the Bzl UI.
- hover over a rule/provider/aspect to get documentation about the it (e.g.
- hover over a rule attribute to get documentation about the attribute (e.g.
s*rcs = ["...]).
- hover over a function to get documentation about the function (e.g.
ran*ge(1, 1, 1)).
- completion for core starlark functions (e.g. type
- completion for bazel builtin function/rules/providers/attributes (e.g.
- completion for third-party and custom starlark rules is available on a
F12 on any string literal; if it looks like a relative or canonical bazel
label, will open the corresponding BUILD or source file (works with default and
bzl tool contains a lightweight and fast LRU remote
This "locally-running" remote cache is actually 30% faster than using the
--disk_cache option (and manages disk usage better). If you have multiple
bazel repositories on your workstation (or are frequently switching git
branches) it is highly recommended to run this remote cache locally, at all
The cache implementation also provides nice progress notifications for uploads
with a terminal-based progress bar.
Given that you may or may not have a vscode window running at all times, the
recommended strategy is to keep a terminal running (or system service) with
/path/to/bzl cache --progress and put the following in your
This will give a nice speedup for many actions that you'd otherwise be waiting
to unnecessarily rebuild.
The bazel tool provides a view of the
bazel info for a workspace. It is also
used to configure default build/test flags used on conjuction with the language
server (see Starlark Language Server).
The account tool is used to view account settings and/or signup for a pro
subscription. If you and your team members are using the
extension at work, please encourage your product owner / manager / corp-entity
to get your team signed up.
pro subscriptions include:
- Autocompletion, hover documentation, and jump-to-definition for
third-party/custom rulesets. For example, this will automagically produce
autocompletion for a
go_binary rule from
or for a
//bazel/internal/corp.bzl. [COMING SOON].
- Invocation details and build events within VSCode.
- Execution log diff tool.
- Running the
bzl tool as a service within your organization to share
invocation details (as a developer support tool).
- Using the
bzl cache tool in CI.
- User support via slack.
bzl tool runs a webserver by default at
http://localhost:8080. The UI
provides a navigable display of core bazel concepts such as:
- Show bazel workspaces on current machine.
- Show packages within a workspace.
- Show rules within a workspace (by type).
- Show attributes of a rule.
- Show external workspaces.
- Codesearch UI.
- Clickable dependency graph.
The UI is intended to be used as a form of documentation for the workspace to
assist with code presentations, code review, and onboarding of new team members.
The code search tool implements a fast search code search engine. If you are
familiar with livegrep, this is like
livegrep for bazel queries. The backend is not actually livegrep, but a custom
regexp implementation similar to
google/codesearch with an API similar to
Bzl codesearch is unlike any other codesearch tool as it naturally includes all
source file dependencies in the query.
Using codesearch is a two-step process:
- Build a search file index.
- Run queries against the index.
The codesearch UI will guide you through that process. See the docs for
Codesearch for more details.
The build event service configured the display of build events within VSCode.
The invocation service tool allows you to view and/or replay invocations.
The event stream service tool provide a realtime view of build events for build
- syntax highlighting
- hover to get flag reference & links to bazel docs / bazel codesearch