rinne_types/graph.rs
1//! The `CodeGraph` trait seam and shared graph types.
2//!
3//! `SymbolRef` and `Neighborhood` live here so that `rinne-loop`/`rinne-conductor`
4//! can depend on the trait without depending on `rinne-graph`. The concrete
5//! implementation lives in `rinne-graph` behind a `Mutex<Store>`.
6
7use serde::{Deserialize, Serialize};
8
9/// A lightweight reference to a symbol: name, file path, and line number.
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11pub struct SymbolRef {
12 pub name: String,
13 pub file: String,
14 pub line: u32,
15}
16
17/// The structural neighborhood of a symbol: its definition site plus all
18/// callers, callees, and imports known to the index.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct Neighborhood {
21 pub definition: SymbolRef,
22 pub callers: Vec<SymbolRef>,
23 pub callees: Vec<SymbolRef>,
24 pub imports: Vec<SymbolRef>,
25 /// `true` when the underlying file has been modified since the last index run.
26 pub stale: bool,
27}
28
29/// Read-only view over the code graph. Implementations must be `Send + Sync`
30/// so they can be shared across async task boundaries.
31pub trait CodeGraph: Send + Sync {
32 /// Returns the neighborhood of the first symbol matching `symbol`, or `None`
33 /// if the symbol is not in the index.
34 fn neighborhood(&self, symbol: &str) -> Option<Neighborhood>;
35
36 /// Returns the first symbol named `name` defined in `file`, or `None`.
37 fn resolve_in_file(&self, file: &str, name: &str) -> Option<SymbolRef>;
38
39 /// Returns the names of every symbol currently in the index.
40 fn symbol_names(&self) -> Vec<String>;
41}