VS Code Extension
The Bazelle VS Code extension provides seamless integration with the Bazelle CLI, allowing you to manage BUILD files directly from your editor.
Features
- Commands: Run all Bazelle commands from the Command Palette
- Status Bar: Visual indicator showing Bazelle status and quick actions
- Watch Mode: Automatically update BUILD files when source files change
- Auto-Update: Optionally update BUILD files on save
- Starlark Syntax: Full syntax highlighting for BUILD files,
.bzl, andMODULE.bazel - Bundled Binary: Extension includes pre-built Bazelle binaries (no separate installation needed)
Installation
Search for “Bazelle” in the VS Code Extensions panel, or:
code --install-extension bazelle.bazelleDownload and install the latest nightly build:
# Download the nightly VSIXcurl -fsSLO https://github.com/albertocavalcante/bazelle/releases/download/nightly/bazelle-nightly.vsix
# Install the extensioncode --install-extension bazelle-nightly.vsixDownload a specific version from the Releases page:
# Download a specific versioncurl -fsSLO https://github.com/albertocavalcante/bazelle/releases/download/v0.1.0/bazelle-0.1.0.vsix
# Install the extensioncode --install-extension bazelle-0.1.0.vsixCommands
Access all commands via the Command Palette (Cmd+Shift+P / Ctrl+Shift+P):
| Command | Description |
|---|---|
Bazelle: Update BUILD Files | Run bazelle update on the workspace |
Bazelle: Update BUILD Files (Incremental) | Update only changed directories |
Bazelle: Fix BUILD Files | Run bazelle fix (may make breaking changes) |
Bazelle: Fix BUILD Files (Dry Run) | Preview fix changes without applying |
Bazelle: Show Status | Show which directories have stale BUILD files |
Bazelle: Start Watch Mode | Watch for changes and auto-update |
Bazelle: Stop Watch Mode | Stop the file watcher |
Bazelle: Initialize Project | Run bazelle init to set up a new project |
Bazelle: Show Output | Open the Bazelle output channel |
Bazelle: Download Binary | Download the Bazelle binary for your platform |
Bazelle: Start Daemon | Start the bazelle daemon process |
Bazelle: Stop Daemon | Stop the running daemon |
Bazelle: Daemon Status | Show daemon status and info |
Bazelle: Restart Daemon | Restart the daemon |
Configuration
Configure the extension in your VS Code settings (settings.json):
{ // Path to the bazelle executable (default: uses bundled or PATH) "bazelle.path": "bazelle",
// Automatically update BUILD files when saving source files "bazelle.autoUpdate": false,
// When to show the status bar item // Options: "always", "onBazelWorkspace", "never" "bazelle.statusBar.show": "onBazelWorkspace",
// Start watch mode automatically when opening a Bazel workspace "bazelle.watch.enabled": false,
// Debounce delay for watch mode (milliseconds) "bazelle.watch.debounceMs": 500,
// Enable daemon mode (falls back to subprocess if unavailable) "bazelle.daemon.enabled": true,
// Custom daemon socket path (default: ~/.bazelle/daemon.sock) "bazelle.daemon.socketPath": null,
// Automatically start daemon if not running "bazelle.daemon.autoStart": false}Settings Reference
bazelle.path
Path to the Bazelle executable. The extension resolves the binary in this order:
- Configured path: Uses
bazelle.pathif it’s an absolute path or found in PATH - System PATH: Looks for
bazellein your system PATH - Bundled binary: Uses the binary bundled with the extension (platform-specific)
- Download prompt: Offers to download the binary from GitHub releases
bazelle.autoUpdate
When enabled, the extension automatically runs bazelle update when you save a source file (.go, .kt, .py, etc.). This is useful for keeping BUILD files in sync as you code.
bazelle.statusBar.show
Controls when the status bar item is visible:
always: Always show the status bar itemonBazelWorkspace: Only show when the workspace contains Bazel files (default)never: Never show the status bar item
bazelle.watch.enabled
When enabled, the extension starts watch mode automatically when you open a Bazel workspace. Watch mode monitors source files and updates BUILD files when changes are detected.
bazelle.watch.debounceMs
How long to wait (in milliseconds) after a file change before running the update. This prevents running multiple updates when saving multiple files quickly. Default: 500ms.
bazelle.daemon.enabled
When enabled (default), the extension attempts to connect to the bazelle daemon for watch mode. If the daemon is not running, it falls back to subprocess mode. The daemon provides better performance by eliminating startup overhead.
bazelle.daemon.socketPath
Custom path to the daemon socket. By default, uses ~/.bazelle/daemon.sock. Only change this if you’re running the daemon with a custom socket path.
bazelle.daemon.autoStart
When enabled, the extension will automatically start the daemon if it’s not already running when you start watch mode. Default: false.
Daemon Mode
The extension can operate in two modes for watch functionality:
Daemon Mode (Recommended)
The daemon is a background process that provides:
- Zero startup overhead: Already running, instant responses
- Multi-client support: CLI, VS Code, and other tools share one process
- Efficient file watching: Single shared file watcher
To use daemon mode:
- Start the daemon from terminal:
bazelle daemon start - In VS Code, run “Bazelle: Start Watch Mode”
- The extension connects to the daemon automatically
Subprocess Mode (Fallback)
If the daemon is unavailable, the extension falls back to spawning bazelle watch as a subprocess. This works but has more overhead.
Checking the Active Mode
- Open the Output panel (“Bazelle: Show Output”)
- Look for
[Daemon] Connected to bazelle daemon(daemon mode) orStarting watch mode (subprocess)(subprocess mode)
Status Bar
The status bar shows the current Bazelle status:
| Icon | Status | Description |
|---|---|---|
$(check) | Ready | Bazelle is ready, BUILD files are up to date |
$(sync~spin) | Running | Bazelle is currently running |
$(eye) | Watching | Watch mode is active |
$(warning) | Stale | Some BUILD files may be out of date |
$(error) | Error | Last command failed |
Click the status bar item to open a quick-pick menu with common actions.
Starlark Syntax Highlighting
The extension provides syntax highlighting for:
BUILDandBUILD.bazelfiles.bzlfiles (Starlark macros and rules)WORKSPACEandWORKSPACE.bazelfilesMODULE.bazelfiles
The grammar supports:
- Keywords (
load,def,if,for,in, etc.) - Built-in functions (
rule,provider,select, etc.) - Bazel-specific constructs (
Label,struct,depset) - String interpolation and raw strings
- Comments (line and block)
Workspace Detection
The extension automatically activates when it detects a Bazel workspace. It looks for:
MODULE.bazel(bzlmod)WORKSPACEorWORKSPACE.bazel(legacy)BUILDorBUILD.bazelfiles.bazelle/config.toml(Bazelle config)
Troubleshooting
Binary not found
If you see “Bazelle binary not found”:
- Run
Bazelle: Download Binaryfrom the Command Palette - Or install Bazelle manually and set
bazelle.pathto the absolute path
Commands not working
- Check the Output panel (
Bazelle: Show Output) for error messages - Verify Bazelle works from the terminal:
bazelle version - Check that you’re in a Bazel workspace (has
MODULE.bazelorWORKSPACE)
Watch mode not detecting changes
- Increase
bazelle.watch.debounceMsif updates are too frequent - Check that the file patterns match your source files
- Verify the workspace is correctly detected
Daemon connection issues
“Failed to connect to daemon”:
- Check if daemon is running:
bazelle daemon status - If not running, start it:
bazelle daemon start - Check the Output panel for detailed error messages
Watch mode falling back to subprocess:
This happens when the daemon is unavailable. To use daemon mode:
# Start the daemonbazelle daemon start
# Verify it's runningbazelle daemon status“Connection lost” or frequent disconnects:
- Check daemon logs:
tail -f ~/.bazelle/daemon.log - Restart the daemon:
bazelle daemon restart - If issues persist, run in foreground to debug:
bazelle daemon start --foreground
Socket permission errors:
# Check socket permissionsls -la ~/.bazelle/daemon.sock
# Should show owner-only permissions (srw-------)# If wrong, clean up and restart:rm -f ~/.bazelle/daemon.sock ~/.bazelle/daemon.pidbazelle daemon startBuilding from Source
To build the extension from source:
cd editors/code
# Install dependenciesbun install
# Buildbun run build
# Package as VSIXbun run packageThe VSIX file will be created in the editors/code directory.