A comprehensive VS Code extension that provides full support for Bazel build system integration, including Java language support, project management, and development tools.
- Automatic Workspace Detection: Automatically detects Bazel workspaces by looking for
WORKSPACE
orWORKSPACE.bazel
files - Project View Management: Creates and manages
.bazelproject
files for optimal project structure - Multi-Root Workspace Support: Convert single-root workspaces to multi-root for better organization
- File Watcher Optimization: Automatically configures file watchers to only monitor relevant directories
- Starlark Syntax Highlighting: Full syntax highlighting for Bazel build files (
.BUILD
,.WORKSPACE
,.bzl
,.bazel
,.bzlmod
,.sky
,.star
) - Bazel Project File Support: Syntax highlighting for
.bazelproject
files - Language Configuration: Proper indentation, bracket matching, and comment support for Starlark files
- Buildifier Integration: Automatic code formatting for Starlark files using the
buildifier
tool - Format on Save: Automatically format Bazel files when saving (configurable)
- Custom Buildifier Path: Support for custom buildifier binary locations
- Bazel Run Targets View: Visual tree view of all available Bazel run targets in the Explorer
- Task Execution: Run Bazel targets directly from the VS Code interface
- Task Monitoring: Real-time status tracking of running Bazel tasks
- Task Control: Start, stop, and refresh Bazel tasks with intuitive controls
- Project View Sync: Synchronize project structure based on
.bazelproject
file changes - Automatic Sync Notifications: Get notified when project view changes and choose to sync
- Java Project Integration: Seamless integration with the Bazel Java Language Server
- Dependency Resolution: Automatic classpath and dependency resolution using Bazel BUILD files
- Bazel Run Targets Panel: Dedicated panel in the Explorer showing all available run targets
- Context-Aware Commands: Commands that adapt based on workspace state and file context
- Status Indicators: Visual indicators for running tasks and sync status
- Multi-Root Workspace Conversion: One-click conversion to multi-root workspace format
- Logging Control: Configurable log levels (debug, warn, info, error, trace)
- Project View Settings: Control automatic opening and notification behavior
- Buildifier Settings: Enable/disable formatting and configure binary path
- Import Control: Option to disable Bazel importer functionality
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search for "Bazel extension by Salesforce Engineering"
- Click Install
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search for "sfdc.bazel-vscode-java"
- Click Install
# Clone the repository
git clone https://github.com/salesforce/bazel-vscode.git
# Install dependencies
npm install
# Build the extension
npm run build
# Package the extension
npm run package
- VS Code 1.100.0 or higher
- Bazel build system installed and configured
- Buildifier tool (optional, for code formatting)
- Open a Bazel Workspace: Open VS Code in a directory containing a
WORKSPACE
orWORKSPACE.bazel
file - Automatic Detection: The extension will automatically detect the Bazel workspace
- Project View Creation: If no
.bazelproject
file exists, one will be created automatically - Initial Sync: The extension will perform an initial project synchronization
The extension uses .bazelproject
files to define which directories and targets to include in your VS Code workspace:
directories:
src/main/java
src/test/java
tools
targets:
//src/main/java/com/example:app
//src/test/java/com/example:test
Access these commands via the Command Palette (Ctrl+Shift+P):
Bazel: Sync Project View
: Synchronize the project view with current.bazelproject
fileBazel: Refresh Bazel Run Configs
: Refresh the list of available Bazel run targetsBazel: Run Bazel Target
: Execute a selected Bazel targetBazel: Kill Bazel Target
: Stop a running Bazel targetBazel: Open the Bazel Project View file
: Open the.bazelproject
file for editingBazel: Convert to Multi-Root workspace
: Convert single-root workspace to multi-root format
- Open the Explorer panel (Ctrl+Shift+E)
- Look for the "Bazel Run Targets" section
- Click the refresh button to update the list
- Click the play button next to any target to run it
- Click the stop button to kill a running target
Configure the extension behavior in VS Code settings:
{
"bazel.import.disabled": false,
"bazel.log.level": "info",
"bazel.projectview.open": true,
"bazel.projectview.updateFileWatcherExclusion": true,
"bazel.projectview.notification": true,
"bazel.buildifier.enable": true,
"bazel.buildifier.binary": null
}
bazel.import.disabled
: Disable the Bazel importer functionalitybazel.log.level
: Set logging level (debug, warn, info, error, trace)bazel.projectview.open
: Automatically open the Bazel Project View file on activationbazel.projectview.updateFileWatcherExclusion
: Update file watcher exclusions based on.bazelproject
bazel.projectview.notification
: Show sync notifications when.bazelproject
changesbazel.buildifier.enable
: Enable automatic formatting with buildifierbazel.buildifier.binary
: Custom path to buildifier binary (null = use PATH)
Extension not activating:
- Ensure you're in a Bazel workspace (contains
WORKSPACE
orWORKSPACE.bazel
) - Check VS Code version compatibility (requires 1.100.0+)
Project view not syncing:
- Verify
.bazelproject
file exists and is properly formatted - Check extension logs for error messages
- Try manual sync via Command Palette
Buildifier not working:
- Ensure buildifier is installed and in your PATH
- Check buildifier binary path in settings
- Verify buildifier permissions
Enable debug logging to troubleshoot issues:
- Open VS Code settings
- Set
bazel.log.level
todebug
- Open the Output panel (View โ Output)
- Select "Bazel" from the dropdown
- Check for error messages and debug information