Commit ada202e
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- src
- index
- server
7 files changed
+621
-265
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
| 195 | + | |
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| |||
0 commit comments