A Build Server Protocol (BSP) implementation that enables SourceKit LSP integration with Bazel-based Swift projects.
This project bridges the gap between Bazel build systems and SourceKit LSP, providing full IDE functionality (syntax highlighting, code completion, jump to definition, error diagnostics) for Swift projects built with Bazel.
Key Features:
- 🚀 Real-time IDE features for Bazel Swift projects
- 📋 Build Server Protocol 2.0 compliance
- ⚡ Intelligent caching of Bazel query results
- 📝 Comprehensive logging and debugging support
- 🔄 Background target refresh for optimal performance
- macOS 13.0 or later
- Swift 6.1 or later
- Bazel 6.0 or later
- Visual Studio Code with Swift extension (recommended)
# Clone and build
git clone <repository-url>
cd bazel-build-server
swift build --configuration release
# Or use the Makefile
make release
Create a buildServer.json
in your Bazel workspace root:
{
"name": "bazel-sourcekit-bsp",
"argv": ["/path/to/bazel-build-server"],
"version": "1.0.0",
"bspVersion": "2.0.0",
"languages": ["swift"],
"targets": ["//YourApp:YourApp"],
"indexDatabasePath": "/path/to/your/project/.index-db",
"aqueryArgs": []
}
- Open your Bazel workspace in VS Code
- Install the Swift extension
- The build server will automatically be detected via
buildServer.json
Field | Description | Example |
---|---|---|
argv |
Path to the build server executable | ["/usr/local/bin/bazel-build-server"] |
targets |
Bazel targets to track | ["//App:App", "//Tests:Tests"] |
indexDatabasePath |
SourceKit index database location | "/workspace/.index-db" |
aqueryArgs |
Additional Bazel aquery arguments | ["--output=jsonproto"] |
Option 1: System-wide Installation
make install # Installs to /usr/local/bin
Option 2: Local Development
make test-harness # Copies binary to TestHarness directory
# Development build
swift build
# Run tests
swift test
# Clean build artifacts
swift package clean
The TestHarness/
directory contains a complete example Bazel workspace:
cd TestHarness
code . # Open in VS Code to test the integration
Logs are written to:
- Main log:
~/bazel-build-server.log
- Activity log:
~/.bazel-sourcekit-bsp/activity.log
Set log level in the build server for verbose output.
The build server implements a clean separation of concerns:
- JSON-RPC Layer: Handles LSP communication protocol
- Request Processing: Manages BSP method implementations
- Bazel Integration: Executes and caches Bazel queries
- Target Management: Thread-safe target tracking and updates
Build server not starting:
- Verify the
argv
path inbuildServer.json
is correct - Check file permissions on the executable
- Review logs at
~/bazel-build-server.log
No IDE features working:
- Ensure your Bazel targets build successfully
- Verify
targets
array inbuildServer.json
matches your project - Check that the index database path is writable
Performance issues:
- Review
aqueryArgs
for optimization opportunities - Monitor cache hit rates in activity logs
- Consider reducing the number of tracked targets
Recommended extensions for the best experience:
- Swift - Core Swift language support
- SwiftFormat - Code formatting on save
- Error Lens - Inline error display
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass with
swift test
- Submit a pull request
See LICENSE for details.