Skip to content

Commit 8dd6642

Browse files
committed
Update README.md to enhance project overview, quick start instructions, and troubleshooting guidance
1 parent 41fb237 commit 8dd6642

File tree

1 file changed

+150
-13
lines changed

1 file changed

+150
-13
lines changed

README.md

Lines changed: 150 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,159 @@
11
# Bazel SourceKit BSP
22

3-
A build server implementation for SourceKit LSP.
3+
A Build Server Protocol (BSP) implementation that enables SourceKit LSP integration with Bazel-based Swift projects.
44

5-
This allows you to get SourceKit working for Swift projects that use the Bazel build system.
5+
## Overview
66

7-
SourceKit is a language server that provides syntax highlight, jump to definition, auto complete, etc.
7+
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.
88

9-
## Installation
9+
**Key Features:**
10+
- 🚀 Real-time IDE features for Bazel Swift projects
11+
- 📋 Build Server Protocol 2.0 compliance
12+
- ⚡ Intelligent caching of Bazel query results
13+
- 📝 Comprehensive logging and debugging support
14+
- 🔄 Background target refresh for optimal performance
1015

11-
1. clone the project and run swift build, the server executable will be store in the `.build/arm64-apple-macosx/debug/bazel-build-server`
12-
2. edit the buildServer.json under the TestHarness folder by changing the executable path
13-
3. if you use global_index_store, be sure the change the path to the `.index-db`
14-
4. open TestHarness folder with `code TestHarness`
15-
5. the bazel-build-server.log is stored at the user home directory `~/bazel-build-server.log`
16+
## Prerequisites
1617

17-
You can use the example buildServer.json inside the TestHarness for your project and make sure you specify the target name `//YourTarget:YourTarget`
18+
- macOS 13.0 or later
19+
- Swift 6.1 or later
20+
- Bazel 6.0 or later
21+
- Visual Studio Code with Swift extension (recommended)
1822

19-
### Recommended plugins
23+
## Quick Start
2024

21-
- [Swift format](https://github.com/nicklockwood/SwiftFormat). Formats your swift code "on save".
22-
- [Error Lens](https://github.com/usernamehw/vscode-error-lens). Errors and warnings look similar to Xcode.
25+
### 1. Build the Server
26+
27+
```bash
28+
# Clone and build
29+
git clone <repository-url>
30+
cd bazel-build-server
31+
swift build --configuration release
32+
33+
# Or use the Makefile
34+
make release
35+
```
36+
37+
### 2. Configure Your Project
38+
39+
Create a `buildServer.json` in your Bazel workspace root:
40+
41+
```json
42+
{
43+
"name": "bazel-sourcekit-bsp",
44+
"argv": ["/path/to/bazel-build-server"],
45+
"version": "1.0.0",
46+
"bspVersion": "2.0.0",
47+
"languages": ["swift"],
48+
"targets": ["//YourApp:YourApp"],
49+
"indexDatabasePath": "/path/to/your/project/.index-db",
50+
"aqueryArgs": []
51+
}
52+
```
53+
54+
### 3. IDE Setup (VS Code)
55+
56+
1. Open your Bazel workspace in VS Code
57+
2. Install the Swift extension
58+
3. The build server will automatically be detected via `buildServer.json`
59+
60+
## Configuration
61+
62+
### buildServer.json Options
63+
64+
| Field | Description | Example |
65+
|-------|-------------|---------|
66+
| `argv` | Path to the build server executable | `["/usr/local/bin/bazel-build-server"]` |
67+
| `targets` | Bazel targets to track | `["//App:App", "//Tests:Tests"]` |
68+
| `indexDatabasePath` | SourceKit index database location | `"/workspace/.index-db"` |
69+
| `aqueryArgs` | Additional Bazel aquery arguments | `["--output=jsonproto"]` |
70+
71+
### Installation Options
72+
73+
**Option 1: System-wide Installation**
74+
```bash
75+
make install # Installs to /usr/local/bin
76+
```
77+
78+
**Option 2: Local Development**
79+
```bash
80+
make test-harness # Copies binary to TestHarness directory
81+
```
82+
83+
## Development
84+
85+
### Building and Testing
86+
87+
```bash
88+
# Development build
89+
swift build
90+
91+
# Run tests
92+
swift test
93+
94+
# Clean build artifacts
95+
swift package clean
96+
```
97+
98+
### Test Harness
99+
100+
The `TestHarness/` directory contains a complete example Bazel workspace:
101+
102+
```bash
103+
cd TestHarness
104+
code . # Open in VS Code to test the integration
105+
```
106+
107+
### Debugging
108+
109+
Logs are written to:
110+
- **Main log**: `~/bazel-build-server.log`
111+
- **Activity log**: `~/.bazel-sourcekit-bsp/activity.log`
112+
113+
Set log level in the build server for verbose output.
114+
115+
## Architecture
116+
117+
The build server implements a clean separation of concerns:
118+
119+
- **JSON-RPC Layer**: Handles LSP communication protocol
120+
- **Request Processing**: Manages BSP method implementations
121+
- **Bazel Integration**: Executes and caches Bazel queries
122+
- **Target Management**: Thread-safe target tracking and updates
123+
124+
## Troubleshooting
125+
126+
**Build server not starting:**
127+
- Verify the `argv` path in `buildServer.json` is correct
128+
- Check file permissions on the executable
129+
- Review logs at `~/bazel-build-server.log`
130+
131+
**No IDE features working:**
132+
- Ensure your Bazel targets build successfully
133+
- Verify `targets` array in `buildServer.json` matches your project
134+
- Check that the index database path is writable
135+
136+
**Performance issues:**
137+
- Review `aqueryArgs` for optimization opportunities
138+
- Monitor cache hit rates in activity logs
139+
- Consider reducing the number of tracked targets
140+
141+
## VS Code Extensions
142+
143+
Recommended extensions for the best experience:
144+
145+
- **[Swift](https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang)** - Core Swift language support
146+
- **[SwiftFormat](https://github.com/nicklockwood/SwiftFormat)** - Code formatting on save
147+
- **[Error Lens](https://github.com/usernamehw/vscode-error-lens)** - Inline error display
148+
149+
## Contributing
150+
151+
1. Fork the repository
152+
2. Create a feature branch
153+
3. Add tests for new functionality
154+
4. Ensure all tests pass with `swift test`
155+
5. Submit a pull request
156+
157+
## License
158+
159+
See [LICENSE](LICENSE) for details.

0 commit comments

Comments
 (0)