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/// Stable string key for a node. Scheme is the plugin's choice, e.g.
8/// `file:{path}` for a source file, `ext:{name}` for an external library.
9pub type NodeId = String;
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Node {
13    pub id: NodeId,
14    /// The plugin's own vocabulary — "file" today; "module"/"function"/… later.
15    /// The core never interprets this, only stores and projects on it.
16    pub kind: String,
17    pub name: String,
18    /// Containing node, if any (a hard structural link to another node by id —
19    /// e.g. a function's file).
20    #[serde(default, skip_serializing_if = "Option::is_none")]
21    pub parent: Option<NodeId>,
22    /// Free-form attributes (`path`, `loc`, `visibility`, `version`, …, plus
23    /// language-specific keys). The plugin fills structural ones; the
24    /// orchestrator adds computed ones (metrics, cycle) into the same map.
25    /// Described by the level's `node_attributes` dictionary. Flattened into the
26    /// node JSON object.
27    #[serde(flatten)]
28    pub attrs: Attributes,
29}