Skip to main content

code_ranker_plugin_api/
node.rs

1//! The [`Node`] — anything we analyze. Today a source file (`kind == "file"`),
2//! later a folder / module / function / variable / line, with no model change.
3
4use crate::attrs::Attributes;
5use serde::{Deserialize, Serialize};
6
7/// The node `kind` for a source file — the unit every plugin analyzes today.
8/// One source of truth for the literal so plugins don't sprinkle `"file"`.
9pub const FILE: &str = "file";
10/// The node `kind` for a third-party (external) dependency node.
11pub const EXTERNAL: &str = "external";
12
13/// Stable string key for a node. Scheme is the plugin's choice, e.g.
14/// `file:{path}` for a source file, `ext:{name}` for an external library.
15pub type NodeId = String;
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct Node {
19    pub id: NodeId,
20    /// The plugin's own vocabulary — "file" today; "module"/"function"/… later.
21    /// The core never interprets this, only stores and projects on it.
22    pub kind: String,
23    pub name: String,
24    /// Containing node, if any (a hard structural link to another node by id —
25    /// e.g. a function's file).
26    #[serde(default, skip_serializing_if = "Option::is_none")]
27    pub parent: Option<NodeId>,
28    /// Free-form attributes (`path`, `loc`, `visibility`, `version`, …, plus
29    /// language-specific keys). The plugin fills structural ones; the
30    /// orchestrator adds computed ones (metrics, cycle) into the same map.
31    /// Described by the level's `node_attributes` dictionary. Flattened into the
32    /// node JSON object.
33    #[serde(flatten)]
34    pub attrs: Attributes,
35}