Skip to main content

Module imports

Module imports 

Expand description

Architecture import-graph extraction.

Walks each Tier-1 source file at HEAD via tree-sitter, captures every import statement as a raw (src_path, target, kind) row, and bulk-inserts into the imports DuckDB table. Mirrors the shape of crate::clones (per-language dispatch + iterative cursor walker), so the next behavioural-signal addition can follow the same module template.

The extractor leaves every row with resolved = false / target_path = NULL. The companion per-language resolver maps target → tracked repo path and upgrades those columns in place. Downstream analyses (layered-architecture rules, god-class detector, architecture force graph, module chord) all read against this schema.

Structs§

RawImport
One captured import edge — pre-resolution.

Enums§

ImportKind
Coarse import semantics. Closed set so the schema’s CHECK can validate at INSERT time.
ImportLanguage
Tier-1 languages CodeLore extracts import edges from.

Functions§

extract_imports
Parse source under lang’s grammar and collect every import edge it carries. Returns an empty vec on parse error (logged at warn level) so a single malformed file doesn’t poison the ingest.
resolve_by_extension
Resolve an import target from importer_path to a tracked path, dispatching to the per-language resolver by the importer’s file extension. Returns None for extensions without a resolver or for unresolvable targets. The single dispatch point shared by the HEAD ingest (resolve_imports_at_head) and the historical scan (architecture-trend), so language coverage — and which extensions route where — is defined in exactly one place.
resolve_java
Resolve a Java import FQN (com.foo.Bar) to a tracked .java file by matching the package/class path as a unique repo-path suffix (com/foo/Bar.java — Java packages map directly to directories). The match must be unique (zero or more than one candidate yields None) so an ambiguous suffix never fabricates an edge; JDK / third-party imports (java.util.List) have no tracked file and resolve to None. Wildcard package imports (com.foo.*) name a directory, not a file, and are skipped. A static-member import (com.foo.Bar.baz) or a nested class (com.foo.Outer.Inner) resolves via a single strip-retry to the enclosing class file — the full path is probed first, so a real inner-class file wins before the strip.
resolve_js_relative
Resolve a JS/TS relative import target against the live-at-HEAD path set. Returns the canonical repo-relative path if a match exists, or None for unresolvable / external imports.
resolve_python_absolute
Resolve an absolute Python module path (mypkg.utils, os) to a tracked file by matching the dotted path as a repo-path suffix (a/b/c.py or a/b/c/__init__.py) against the live-at-HEAD set — Python has no explicit import root, so the module may live under any source prefix. The match must be unique: zero or more than one candidate yields None, so an ambiguous suffix never fabricates a false edge and stdlib / third-party modules (no tracked file) resolve to None.
resolve_python_relative
Resolve a Python relative-import target (e.g. .foo.bar, ..pkg.x) against the live-at-HEAD path set. Handles both from . import foo and from .foo import bar shapes via the dot-prefix convention. External imports (no leading dot) return None.
resolve_rust_path
Resolve a Rust use path against the live-at-HEAD set. Handles the conventional crate::foo::barsrc/foo/bar.rs | src/foo/bar/mod.rs mapping. self:: and super:: resolve relative to the importer’s module directory (see [module_dir]), which is the sibling foo/ for a non-mod.rs foo.rs; each leading super climbs one further level. External crates (anything not starting with crate::/self::/super::) return None.