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

@@ -93,12 +93,13 @@ TEST_CASE(BuildPCHRequest) {
bool test_done = false;
w.run([&]() -> et::task<> {
worker::BuildPCHParams params;
worker::BuildParams params;
params.kind = worker::BuildKind::BuildPCH;
params.file = hdr;
params.directory = "/tmp";
params.arguments =
{"clang++", "-resource-dir", std::string(resource_dir()), "-x", "c++-header", hdr};
params.content = "#pragma once\nint pch_global = 42;\n";
params.text = "#pragma once\nint pch_global = 42;\n";
params.output_path = tmp.path("test_pch.pch");
auto result = co_await w.peer->send_request(params);
@@ -108,7 +109,7 @@ TEST_CASE(BuildPCHRequest) {
co_return;
}
EXPECT_TRUE(result.value().success);
EXPECT_FALSE(result.value().pch_path.empty());
EXPECT_FALSE(result.value().output_path.empty());
test_done = true;
w.peer->close_output();
});
@@ -127,7 +128,8 @@ TEST_CASE(IndexRequest) {
bool test_done = false;
w.run([&]() -> et::task<> {
worker::IndexParams params;
worker::BuildParams params;
params.kind = worker::BuildKind::Index;
params.file = src;
params.directory = "/tmp";
params.arguments = make_args(src);
@@ -161,7 +163,8 @@ TEST_CASE(BuildPCMRequest) {
bool test_done = false;
w.run([&]() -> et::task<> {
worker::BuildPCMParams params;
worker::BuildParams params;
params.kind = worker::BuildKind::BuildPCM;
params.file = src;
params.directory = "/tmp";
params.arguments = {"clang++",
@@ -194,8 +197,9 @@ TEST_CASE(CompletionRequest) {
bool test_done = false;
w.run([&]() -> et::task<> {
worker::CompletionParams params;
params.path = src;
worker::BuildParams params;
params.kind = worker::BuildKind::Completion;
params.file = src;
params.version = 1;
params.text = text;
params.directory = "/tmp";
@@ -223,8 +227,9 @@ TEST_CASE(SignatureHelpRequest) {
bool test_done = false;
w.run([&]() -> et::task<> {
worker::SignatureHelpParams params;
params.path = src;
worker::BuildParams params;
params.kind = worker::BuildKind::SignatureHelp;
params.file = src;
params.version = 1;
params.text = text;
params.directory = "/tmp";
@@ -259,7 +264,8 @@ TEST_CASE(MultipleStatelessRequests) {
w.run([&]() -> et::task<> {
// Send multiple index requests to test stateless worker handles them sequentially.
for(int i = 0; i < 3; i++) {
worker::IndexParams params;
worker::BuildParams params;
params.kind = worker::BuildKind::Index;
params.file = paths[i];
params.directory = "/tmp";
params.arguments = make_args(paths[i]);