Expand description
Deterministic structure extraction for source files.
Bytes in, facts out. This crate never opens a file, never walks a directory and never touches a database: everything it knows about the surrounding tree arrives through the caller’s closures. That is what makes the resulting graph reproducible — two runs over the same working tree produce byte-identical facts.
§What comes out
extract turns one file’s bytes into a FileFacts: a content hash, a
line count, the symbols defined in the file (qualified in-file, with their
doc line, signature and outgoing calls), the imports as written, and — for
Markdown — headings, mentions and the body text.
§Resolving what came out
The extraction step deliberately keeps raw text. resolve_import,
resolve_mention and resolve_call turn that raw text into paths and
symbol keys, using caller-supplied lookups:
known(path)— true whenpathnames a file in the working tree.files_in(dir)— the working-tree paths of the files directly insidedir, empty when the directory does not exist.by_basename(name)— every working-tree path whose file name isname.
All paths, in and out, are working-tree-relative files that use /
separators. No result is ever a directory.
SymbolIndex keys are <file path>#<qualified symbol name>; the caller
builds the index in that shape so resolve_call can prefer a definition
in the calling file or its directory. resolve_call also takes the
calling file’s resolved imports, which is what lets a call reach a
definition in another crate whose name is not unique repository-wide — and
is the only thing that can reach one at all for a call written on a
receiver, which never falls back to repository-wide uniqueness.
A method is stored qualified — Store.flush — and written on a receiver —
store.flush() — so the index files it under the bare name too. Those
entries are read only where the receiver identifies the type, because
stripping a receiver says which method is wanted and nothing about what it
belongs to: see resolve_call.
§Determinism
Every returned collection is sorted and deduplicated, and nothing depends
on hash-map iteration order. Output is capped so a pathological file cannot
blow up the store: see MAX_FILE_BYTES, MAX_BODY_BYTES,
MAX_TEXT_CHARS and MAX_CALLS.
Structs§
- Call
Fact - One call as written, and enough about how it was written to resolve it.
- Call
Scope - What the calling file can see, beyond the symbol index itself.
- File
Facts - Everything one file contributes to the graph.
- Import
Fact - One import as written in the source.
- Symbol
Fact - One definition found in a file.
- Symbol
Index - Symbol keys grouped by symbol name, built by the caller.
Enums§
- Lang
- The languages this crate can read.
Constants§
- MAX_
BODY_ BYTES - Upper bound on the stored Markdown body, in bytes.
- MAX_
CALLS - Upper bound on the calls recorded for one symbol.
- MAX_
FILE_ BYTES - Files larger than this are reduced to hash, language and line count.
- MAX_
TEXT_ CHARS - Upper bound, in characters, on a symbol signature or doc line.
- PARSE_
BUDGET_ MS - Wall-clock budget for parsing one file.
Functions§
- call_
lookup_ names - Every name
resolve_callmay lookcalleeup under in the index. - extract
- Extract the facts for one file.
- indexed_
under - Every name
SymbolIndexfiles a definition callednameunder. - lang_of
- Classify a path by its extension. Unknown extensions are
Lang::Other, which yields hash-only facts. - resolve_
call - Resolve a callee written in
from_fileto the key of the symbol it names. - resolve_
import - Resolve one import to the working-tree paths it names.
- resolve_
mention - Resolve a Markdown mention to a working-tree path.
- written_
as_ method - Whether a callee as written names a receiver rather than a path.