refactor(server): extract Indexer and Compiler from MasterServer (#403)

## Summary

- **Extract `Indexer` class** — owns all index state (ProjectIndex,
MergedIndex shards, OpenFileIndex) and query methods (definition,
references, call/type hierarchy, workspace symbol search)
- **Extract `Compiler` class** — owns document state, PCH/PCM cache,
compile argument resolution, header context, `ensure_compiled`, and
worker forwarding
- **MasterServer is now a pure LSP handler registration layer** (~700
lines, down from ~3200)
- **`MergedIndexShard`** wraps `index::MergedIndex` with a lazily-cached
PositionMapper; `OpenFileIndex` gains matching
`find_occurrence()`/`find_relations()` APIs — callers get pre-converted
LSP ranges directly
- **Indexer returns typed values** (`vector<Location>`,
`vector<CallHierarchyIncomingCall>`, etc.) instead of pre-serialized
JSON, fixing the references handler from JSON string surgery to simple
vector concatenation
- **Fix**: duplicate `workspace/symbol` loop in the original code

## Test plan

- [x] 465 unit tests pass
- [x] 113 integration tests pass
- [x] 2/2 smoke tests pass
- [x] `clang-format` applied

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Server-side C++ compilation orchestration (module & precompiled header
builds) with LSP-integrated document handling.

* **Improvements**
* Deterministic, persistent, dependency-aware caching to avoid redundant
rebuilds and speed up incremental work.
* Better cross-file indexing and navigation, improved diagnostics and
more reliable include/import-aware completions.

* **Tests**
  * Unit tests updated to the unified worker query/build request shapes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
ykiko
2026-04-07 13:30:12 +08:00
committed by GitHub
parent ada202e489
commit bb0b160a28
14 changed files with 3359 additions and 3612 deletions

View File

@@ -39,7 +39,8 @@ TEST_CASE(BuildPCMThenCompileWithImport) {
bool phase1_done = false;
sl.run([&]() -> et::task<> {
worker::BuildPCMParams params;
worker::BuildParams params;
params.kind = worker::BuildKind::BuildPCM;
params.file = iface;
params.directory = "/tmp";
params.arguments = {"clang++",
@@ -54,7 +55,7 @@ TEST_CASE(BuildPCMThenCompileWithImport) {
auto result = co_await sl.peer->send_request(params);
CO_ASSERT_TRUE(result.has_value());
CO_ASSERT_TRUE(result.value().success);
pcm_path = result.value().pcm_path;
pcm_path = result.value().output_path;
EXPECT_FALSE(pcm_path.empty());
phase1_done = true;
@@ -125,7 +126,8 @@ TEST_CASE(BuildPCMChainThenCompile) {
sl.run([&]() -> et::task<> {
// Build PCM for A first.
{
worker::BuildPCMParams params;
worker::BuildParams params;
params.kind = worker::BuildKind::BuildPCM;
params.file = mod_a;
params.directory = "/tmp";
params.arguments = {"clang++",
@@ -139,12 +141,13 @@ TEST_CASE(BuildPCMChainThenCompile) {
auto result = co_await sl.peer->send_request(params);
CO_ASSERT_TRUE(result.has_value() && result.value().success);
pcm_a = result.value().pcm_path;
pcm_a = result.value().output_path;
}
// Build PCM for B, passing A's PCM (transitive dep).
{
worker::BuildPCMParams params;
worker::BuildParams params;
params.kind = worker::BuildKind::BuildPCM;
params.file = mod_b;
params.directory = "/tmp";
params.arguments = {"clang++",
@@ -161,7 +164,7 @@ TEST_CASE(BuildPCMChainThenCompile) {
auto result = co_await sl.peer->send_request(params);
CO_ASSERT_TRUE(result.has_value() && result.value().success);
pcm_b = result.value().pcm_path;
pcm_b = result.value().output_path;
}
pcm_done = true;
@@ -225,7 +228,8 @@ TEST_CASE(ModuleImplementationUnitWithWorker) {
bool pcm_done = false;
sl.run([&]() -> et::task<> {
worker::BuildPCMParams params;
worker::BuildParams params;
params.kind = worker::BuildKind::BuildPCM;
params.file = iface;
params.directory = "/tmp";
params.arguments = {"clang++",
@@ -239,7 +243,7 @@ TEST_CASE(ModuleImplementationUnitWithWorker) {
auto result = co_await sl.peer->send_request(params);
CO_ASSERT_TRUE(result.has_value() && result.value().success);
pcm_path = result.value().pcm_path;
pcm_path = result.value().output_path;
pcm_done = true;
sl.peer->close_output();