mirror of
https://github.com/safishamsi/graphify.git
synced 2026-10-14 07:59:40 +00:00
The Rust extractor gated every non-function item on struct_item,
enum_item and trait_item, so tree-sitter-rust's static_item and
const_item never produced a node: a constant existed in the graph only
through the files that referenced it, never from the Rust that defines
it (0 of 783 names in a jdx/mise snapshot).
Add a branch for both node types: a module-level declaration gets a
node with a file-level contains edge, an associated const inside an
impl is attributed to the impl like a method, and the declared type is
referenced the way a struct field type is.
Fixes #3471
(cherry picked from commit 70ff464064)
69 lines
1.2 KiB
Rust
69 lines
1.2 KiB
Rust
use std::collections::HashMap;
|
|
|
|
pub static RETRY_LIMIT: usize = 3;
|
|
pub const DEFAULT_MODE: &str = "fast";
|
|
const NODE_LIMIT: Limit = Limit(3);
|
|
|
|
struct Limit(usize);
|
|
|
|
struct Graph {
|
|
nodes: HashMap<String, Vec<String>>,
|
|
}
|
|
|
|
impl Graph {
|
|
const CAPACITY: usize = 16;
|
|
|
|
fn new() -> Self {
|
|
Graph { nodes: HashMap::new() }
|
|
}
|
|
|
|
fn add_node(&mut self, id: String) {
|
|
self.nodes.insert(id, vec![]);
|
|
}
|
|
|
|
fn add_edge(&mut self, src: String, tgt: String) {
|
|
self.nodes.entry(src).or_default().push(tgt);
|
|
}
|
|
}
|
|
|
|
fn build_graph(edges: Vec<(String, String)>) -> Graph {
|
|
let mut g = Graph::new();
|
|
for (src, tgt) in edges {
|
|
g.add_edge(src, tgt);
|
|
}
|
|
g
|
|
}
|
|
|
|
trait Processor {
|
|
fn run(&self);
|
|
}
|
|
|
|
trait Logger: Processor {
|
|
fn log(&self);
|
|
}
|
|
|
|
struct Result<T> {
|
|
value: T,
|
|
}
|
|
|
|
struct DataProcessor {
|
|
current: Result<DataProcessor>,
|
|
}
|
|
|
|
impl Processor for DataProcessor {
|
|
fn run(&self) {}
|
|
}
|
|
|
|
impl DataProcessor {
|
|
fn build(input: DataProcessor) -> Result<DataProcessor> {
|
|
Result { value: input }
|
|
}
|
|
}
|
|
|
|
enum GraphEvent {
|
|
NodeAdded(Graph),
|
|
Processed { proc: DataProcessor },
|
|
}
|
|
|
|
struct GraphPair(Graph, Result<DataProcessor>);
|