Skip to main content

Crate code_ranker_graph

Crate code_ranker_graph 

Source
Expand description

Operations over the generic property-graph model defined in code-ranker-plugin-api: cycle detection, Henry-Kafura coupling, aggregate stats, id relativization, and the serializable Snapshot artifact.

Everything here is language-agnostic. Plugins emit a pure api::Graph (structure only); this crate and the orchestrator enrich it (writing computed values into node attrs by id) and assemble the snapshot. Which edge kinds count as information flow is read from the level’s edge_kinds (EdgeKindSpec.flow), passed in as a flow_kinds set — there is no hardcoded uses/contains knowledge.

Re-exports§

pub use attrs::num_attr;
pub use attrs::round_sig3;
pub use cycles::annotate_cycles;
pub use finalize::finalize_graph;
pub use hk::annotate_hk;
pub use level_graph::CycleGroup;
pub use level_graph::LevelGraph;
pub use level_graph::LevelUi;
pub use metrics::FileMetrics;
pub use metrics::metric_specs;
pub use metrics::write_metrics;
pub use relativize::relativize_graph;
pub use relativize::relativize_level;
pub use serialize::to_canonical_string;
pub use serialize::to_canonical_string_pretty;
pub use snapshot::GitInfo;
pub use snapshot::Snapshot;
pub use snapshot::StageTime;
pub use stats::compute_stats;

Modules§

attrs
Shared attribute helpers used by every enrichment pass: numeric rounding, the f64 → AttrValue bridge, typed attribute reads, and the external-node predicate. This is a leaf module — it depends only on the plugin API, never on the crate root, so the enrichment passes can pull helpers from here without creating a submodule → crate-root back-edge.
cycles
Cycle detection over information-flow edges (Kosaraju SCC). Edges count iff their kind is in flow_kinds (derived from EdgeKindSpec.flow); structural kinds like contains are excluded, so a mod foo; parent/child pair is not flagged as a false cycle.
finalize
Canonicalize a freshly-parsed structural graph: drop self-loops, deduplicate edges on (source, target, kind), and prune external nodes that nothing references. Structural edges (e.g. contains) are preserved — they carry no flow but are kept for display and ownership.
hk
Henry-Kafura coupling over flow edges. For each internal (non-external) node we count unique flow partners (fan_in / fan_out), track outgoing edges to external libraries separately (fan_out_external), and compute hk = sloc · (fan_in · fan_out)². Results are written into node attrs as flat keys; zero values are omitted.
level_graph
Per-level payload types: LevelGraph (one analysis level’s structural graph + semantics dictionaries + computed cycles/stats/UI), LevelUi (computed UI hints), and CycleGroup (one classified SCC). These are the widely-imported model types; keeping them in their own module spreads their fan-in off the crate’s snapshot artifact.
metrics
Language-neutral complexity-metric scaffolding: the computed-value carrier FileMetrics, the writer write_metrics (omit-at + LOC/Halstead gating), the no-signal values [metric_omit_at], and the metric attribute catalog metric_specs. The sibling coupling_specs lives alongside it; both are merged into the snapshot’s node-attribute dictionary.
relativize
Id relativization: rewrite absolute file-path node ids to portable {target}/rel / {root}/rel tokens (and follow them through edges, parents, cycle node lists, and external path attributes), so a snapshot is machine-independent.
serialize
Canonical (deterministic) JSON serialization. Object keys come out alphabetically (serde_json::Value is backed by a BTreeMap) and the nodes/edges arrays are sorted by a stable key, so unchanged input is byte-identical across runs. Generic over any Serialize — depends on nothing else in the crate.
snapshot
The serializable analysis artifact (Snapshot) and its header types (GitInfo, StageTime).
stats
Per-graph aggregate stats: the mean of each tracked numeric metric across the project’s file nodes. Zero/missing values are excluded from a metric’s average (matching the historical behavior); a metric is emitted only when its average is positive.

Functions§

coupling_specs
The coupling/cycle attribute dictionary produced by annotate_hk / annotate_cycles, plus the coupling group. The orchestrator merges these into each level’s node_attributes / attribute_groups.