Skip to content

Commit ada202e

Browse files
16bit-ykikoclaude
andauthored
feat(index): piggyback indexing on PCH/PCM builds and open-file compiles (#402)
## Summary Piggyback index construction onto existing compilation steps, eliminating redundant recompilation in background indexing: - **`TUIndex::build` gains `interested_only` parameter**: `true` traverses only the main file's top-level decls; `false` (default) traverses the full AST - **PCH build indexes preamble headers**: stateless worker calls `TUIndex::build(unit)` (full traversal) after successful `BuildPCH`, clears `main_file_index`, serializes and sends back; master merges into MergedIndex - **PCM build indexes module interface**: stateless worker calls `TUIndex::build(unit, true)` after successful `BuildPCM`; master merges into MergedIndex - **Open-file compile indexes main file**: stateful worker calls `TUIndex::build(unit, true)` after successful `Compile`, serialized in `CompileResult` - **New `OpenFileIndex` in-memory structure**: master holds `FileIndex + SymbolTable + buffer text` per open file — not persisted to disk, not merged, discarded on close - **Dual-source query path**: `query_index_relations`, `lookup_symbol_at_position`, `find_symbol_definition_location`, all hierarchy handlers, and `workspace/symbol` check `OpenFileIndex` first (fresher), then fall back to `MergedIndex` (disk-indexed) - **Background indexing skips open files**: checked via `documents.count()`; on `didClose` the file is re-queued into `index_queue` - **`didSave` re-queues non-open dependents**: dirtied files from `compile_graph->update()` that are not open get pushed into `index_queue` for background re-indexing - **Extract `lookup_occurrence` helper**: binary search + forward scan picking the innermost (narrowest) match, replacing a broken `while/break/break` pattern - **Extract `find_symbol_info` helper**: consolidates 6 duplicated "search open file indices then ProjectIndex" lookups into one method - **`resolve_hierarchy_item` checks open file indices**: no longer limited to ProjectIndex only ## Test plan - [x] 465 unit tests pass - [x] 105 integration tests pass (including all `test_index` cases: GoToDefinition, FindReferences, CallHierarchy, TypeHierarchy, WorkspaceSymbol) - [x] Manual: open a file and immediately use GoToDefinition — should work without waiting for background indexing - [x] Manual: close a file and verify background indexing picks it up and produces a MergedIndex shard 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 836f415 commit ada202e

File tree

7 files changed

+621
-265
lines changed

7 files changed

+621
-265
lines changed

src/index/tu_index.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace {
1414

1515
class Builder : public SemanticVisitor<Builder> {
1616
public:
17-
Builder(TUIndex& result, CompilationUnitRef unit) :
18-
SemanticVisitor<Builder>(unit, false), result(result) {
17+
Builder(TUIndex& result, CompilationUnitRef unit, bool interested_only) :
18+
SemanticVisitor<Builder>(unit, interested_only), result(result) {
1919
result.graph = IncludeGraph::from(unit);
2020
}
2121

@@ -188,11 +188,11 @@ std::array<std::uint8_t, 32> FileIndex::hash() {
188188
return hasher.final();
189189
}
190190

191-
TUIndex TUIndex::build(CompilationUnitRef unit) {
191+
TUIndex TUIndex::build(CompilationUnitRef unit, bool interested_only) {
192192
TUIndex index;
193193
index.built_at = unit.build_at();
194194

195-
Builder builder(index, unit);
195+
Builder builder(index, unit, interested_only);
196196
builder.build();
197197

198198
return index;

src/index/tu_index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct TUIndex {
8585

8686
FileIndex main_file_index;
8787

88-
static TUIndex build(CompilationUnitRef unit);
88+
static TUIndex build(CompilationUnitRef unit, bool interested_only = false);
8989

9090
void serialize(llvm::raw_ostream& os) const;
9191

0 commit comments

Comments
 (0)