Skip to main content

Module code_index

Module code_index 

Source
Expand description

Code index host capability.

Ports the deterministic trigram/word index that lived in Sources/BurinCodeIndex/ on the Swift side. Exposes five host builtins whose surfaces are locked by schemas/code_index/<method>.json:

BuiltinWhat it does
hostlib_code_index_queryTrigram-accelerated literal substring search.
hostlib_code_index_rebuildWalk a workspace and (re)build the in-memory index.
hostlib_code_index_statsCount files/trigrams/words + last rebuild timestamp.
hostlib_code_index_imports_forImports declared by a single file (with resolutions).
hostlib_code_index_importers_ofReverse lookup: who imports the given module/path?

The capability owns one SharedIndex cell per instance — there is at most one live workspace per VM at a time. The schema for the read builtins (query, stats, imports_for, importers_of) does not carry a workspace argument, so multi-workspace embedders are expected to drive separate CodeIndexCapability handles. The internal layout still keeps everything keyed on FileId, so a future schema bump can add a root parameter without refactoring the data model.

Structs§

BuildOutcome
Summary returned from IndexState::build_from_root.
CodeIndexCapability
Code-index capability handle.
DepGraph
Forward + reverse import graph plus the side-table of unresolved import strings (raw text we couldn’t map back to a known file).
IndexState
In-memory index for one workspace. Composed from the per-file table, the trigram + word sub-indexes, and the dep graph.
IndexedFile
Per-file metadata persisted in the index.
IndexedSymbol
Outline-style symbol entry. Reserved for AST integration; the code-index importer leaves IndexedFile::symbols empty, but the shape is kept stable so storage upgrades won’t have to re-key.
TrigramIndex
Trigram posting list: trigram -> set of file ids that contain it, plus a per-file reverse map for cheap re-indexing.
WordHit
Single occurrence of an identifier-shaped token: which file it landed in and on which 1-based line number.
WordIndex
Inverted word index keyed on identifier-shaped tokens.

Type Aliases§

FileId
Monotonically-assigned identifier for a file in the index. Stable across re-indexes of the same path so sub-indexes can key on FileId without invalidating string keys.
SharedIndex
Shared, mutable cell carrying the (at most one) live workspace index. Mutex rather than RwLock because rebuilds flip the slot wholesale — fine-grained concurrency between rebuild + reads is intentionally not supported (the Swift side serialised through a single actor too).