1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-License-Identifier: Apache-2.0
//! # code2graph
//!
//! Source files → structural facts. A purpose-neutral, language-agnostic
//! code-graph extraction library: it turns source code into **symbols**,
//! **references**, and **cross-file edges** as plain data — no storage, no
//! scoring, no embeddings, no judgement. See `README.md` for the design boundary.
//!
//! ## Pipeline
//!
//! ```text
//! source ──[extract]──▶ FileFacts (symbols + references) ──[resolve]──▶ CodeGraph (symbols + edges)
//! ```
//!
//! ```
//! use code2graph::{extract_path, resolve::{Resolver, SymbolTableResolver}};
//!
//! let a = extract_path("src/util.rs", "pub fn helper() {}").unwrap();
//! let b = extract_path("src/main.rs", "pub fn run() { helper() }").unwrap();
//! let graph = SymbolTableResolver.resolve(&[a, b]);
//! assert_eq!(graph.edges.len(), 1); // run --calls--> helper
//! ```
//!
//! ## Design
//!
//! - **Identity** ([`symbol`]) is SCIP-aligned: a symbol is a descriptor path
//! rendering to a stable, human-readable string, so cross-file matching is
//! string equality.
//! - **Resolution** ([`resolve`]) is a tier seam: the fast recall-first
//! [`SymbolTableResolver`] (name matching, all languages, `NameOnly` edges) and
//! the precise scope-aware [`ScopeGraphResolver`] (lexical-scope + import +
//! qualified-path resolution, `Scoped`/`Exact` edges, Rust/Python/TypeScript)
//! emit the
//! **same** schema, tagging every edge with a [`graph::Confidence`] and a
//! [`graph::Provenance`] (which analysis derived it, orthogonal to confidence).
//! A consumer picks the tier; the output shape is identical.
//! - **Cross-language bridges** ([`FfiBridgeResolver`]) link call sites to FFI
//! exports (Rust `#[no_mangle]` → C, today) across a language boundary,
//! deterministically and with honest confidence — composable on top of any tier.
//! - **Incremental maintenance** ([`IncrementalGraph`]) keeps a resolved graph
//! current as files change: each file is resolved in isolation and cross-file
//! edges are stitched on demand, so re-extracting one file rebuilds only that
//! file's subgraph — never the whole workspace.
//! - **No storage, no source bodies** — [`graph::Symbol`]s carry a byte span;
//! consumers slice what they need.
//!
//! ## Coverage
//!
//! All 23 languages ([`lang::Language`]) are implemented end-to-end, each
//! behind the [`extract::Extractor`] trait.
pub use ;
pub use ;
pub use ;
pub use Language;
pub use ;
pub use ;