Skip to main content

cgraph/state/
mod.rs

1#![doc = include_str!("README.md")]
2
3use std::sync::atomic::{AtomicU64, Ordering};
4
5use serde::{Deserialize, Serialize};
6
7pub mod graph;
8
9static NEXT_NODE_ID: AtomicU64 = AtomicU64::new(1);
10
11#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
12pub struct NodeId(pub u64);
13
14impl NodeId {
15    pub(crate) fn next() -> Self {
16        Self(NEXT_NODE_ID.fetch_add(1, Ordering::Relaxed))
17    }
18}
19
20#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
21pub struct SourceLocation {
22    pub uri: String,
23    pub line: Option<u32>,
24    pub character: Option<u32>,
25}
26
27#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
28#[serde(rename_all = "snake_case")]
29pub enum HierarchyKind {
30    Call,
31    Type,
32}
33
34/// Stable semantic identity shared by cache entries and duplicate node instances.
35///
36/// `NodeId` cannot fill this role: the product deliberately allows one symbol to
37/// appear multiple times on the canvas, and every occurrence needs its own id.
38#[derive(Clone, Debug, Eq, Hash, PartialEq)]
39pub struct SymbolIdentity {
40    pub symbol: String,
41    pub kind: HierarchyKind,
42    pub location: Option<SourceLocation>,
43}
44
45#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
46pub enum HierarchyDirection {
47    Incoming,
48    Outgoing,
49}
50
51/// Translation from unbounded canvas coordinates to terminal coordinates.
52///
53/// This intentionally contains no Ratatui `Rect`: layout is a view concern and
54/// the state layer must remain usable by IPC and headless tests.
55#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
56pub struct Viewport {
57    pub offset_x: i32,
58    pub offset_y: i32,
59}
60
61#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
62pub enum LoadState {
63    #[default]
64    NotLoaded,
65    Loading,
66    Loaded,
67    Failed,
68}