From fa75ab9bc09a7a2456e62691c1b904c6b67ea4f7 Mon Sep 17 00:00:00 2001 From: Vincent Esche Date: Wed, 13 Dec 2023 14:26:49 +0100 Subject: [PATCH] Extract modules `crate::command::dependencies::{graph,builder,walker}` to `crate::graph` --- src/command/dependencies.rs | 3 --- src/command/dependencies/command.rs | 9 +++++---- src/command/dependencies/cycles/tri_color.rs | 2 +- src/command/dependencies/filter.rs | 11 +++++------ src/command/dependencies/printer.rs | 7 +++++-- src/{command/dependencies => }/graph.rs | 5 +++++ src/{command/dependencies => graph}/builder.rs | 15 +++++---------- src/{command/dependencies => graph}/walker.rs | 2 +- src/lib.rs | 1 + 9 files changed, 28 insertions(+), 27 deletions(-) rename src/{command/dependencies => }/graph.rs (92%) rename src/{command/dependencies => graph}/builder.rs (98%) rename src/{command/dependencies => graph}/walker.rs (97%) diff --git a/src/command/dependencies.rs b/src/command/dependencies.rs index bbcb9dac..338d3d46 100644 --- a/src/command/dependencies.rs +++ b/src/command/dependencies.rs @@ -4,11 +4,8 @@ pub mod options; -pub(crate) mod builder; pub(crate) mod command; pub(super) mod cycles; pub(super) mod filter; -pub(crate) mod graph; pub(super) mod printer; pub(super) mod theme; -pub(super) mod walker; diff --git a/src/command/dependencies/command.rs b/src/command/dependencies/command.rs index 356d45a0..8696aef1 100644 --- a/src/command/dependencies/command.rs +++ b/src/command/dependencies/command.rs @@ -8,13 +8,14 @@ use petgraph::graph::NodeIndex; use ra_ap_hir as hir; use ra_ap_ide::RootDatabase; -use crate::analyzer::LoadOptions; +use crate::{ + analyzer::LoadOptions, + graph::{Graph, GraphBuilder}, +}; use super::{ - builder::Builder, cycles::tri_color::{CycleDetector, TriColorDepthFirstSearch}, filter::Filter, - graph::Graph, options::{LayoutAlgorithm, Options}, printer::Printer, }; @@ -36,7 +37,7 @@ impl Command { pub fn run(self, krate: hir::Crate, db: &RootDatabase) -> anyhow::Result<()> { trace!("Building graph ..."); - let builder = Builder::new(self.options.clone(), db, krate); + let builder = GraphBuilder::new(db, krate); let (graph, crate_node_idx) = builder.build()?; if self.options.acyclic { diff --git a/src/command/dependencies/cycles/tri_color.rs b/src/command/dependencies/cycles/tri_color.rs index 23bf542a..815ac700 100644 --- a/src/command/dependencies/cycles/tri_color.rs +++ b/src/command/dependencies/cycles/tri_color.rs @@ -20,7 +20,7 @@ use std::{marker::PhantomData, ops::ControlFlow}; use bitvec::vec::BitVec; use petgraph::graph::{IndexType, NodeIndex}; -use super::super::graph::Graph as G; +use crate::graph::Graph as G; struct BitSet { vec: BitVec, diff --git a/src/command/dependencies/filter.rs b/src/command/dependencies/filter.rs index 693df6c1..211c12d9 100644 --- a/src/command/dependencies/filter.rs +++ b/src/command/dependencies/filter.rs @@ -15,14 +15,13 @@ use ra_ap_hir::{self as hir}; use ra_ap_ide_db::RootDatabase; use ra_ap_syntax::ast; -use crate::analyzer; - -use super::{ - graph::{Edge, EdgeKind, Graph}, - options::Options, - walker::GraphWalker, +use crate::{ + analyzer, + graph::{Edge, EdgeKind, Graph, GraphWalker}, }; +use super::options::Options; + #[derive(Debug)] pub struct Filter<'a> { options: &'a Options, diff --git a/src/command/dependencies/printer.rs b/src/command/dependencies/printer.rs index b86bba42..31f1efd8 100644 --- a/src/command/dependencies/printer.rs +++ b/src/command/dependencies/printer.rs @@ -13,10 +13,13 @@ use petgraph::{ use ra_ap_hir as hir; use ra_ap_ide::RootDatabase; -use crate::{analyzer, item::visibility::ItemVisibility}; +use crate::{ + analyzer, + graph::{Edge, EdgeKind, Graph, Node}, + item::visibility::ItemVisibility, +}; use super::{ - graph::{Edge, EdgeKind, Graph, Node}, options::Options, theme::{edge_styles, node_styles}, }; diff --git a/src/command/dependencies/graph.rs b/src/graph.rs similarity index 92% rename from src/command/dependencies/graph.rs rename to src/graph.rs index 42ac3e0f..6813e6a1 100644 --- a/src/command/dependencies/graph.rs +++ b/src/graph.rs @@ -8,6 +8,11 @@ use petgraph::stable_graph::StableGraph; use crate::item::Item; +mod builder; +mod walker; + +pub(crate) use self::{builder::GraphBuilder, walker::GraphWalker}; + pub type Graph = StableGraph; #[derive(Clone, PartialEq, Debug)] diff --git a/src/command/dependencies/builder.rs b/src/graph/builder.rs similarity index 98% rename from src/command/dependencies/builder.rs rename to src/graph/builder.rs index 8f223523..b2d00dd8 100644 --- a/src/command/dependencies/builder.rs +++ b/src/graph/builder.rs @@ -13,11 +13,9 @@ use ra_ap_hir_ty::{self as hir_ty, db::HirDatabase as _, TyExt as _}; use ra_ap_ide_db::{self as ide_db}; use scopeguard::defer; -use crate::item::Item; - -use super::{ +use crate::{ graph::{Edge, EdgeKind, Graph, Node}, - options::Options, + item::Item, }; #[derive(Debug, Hash, Eq, PartialEq)] @@ -27,9 +25,7 @@ struct Dependency { } #[derive(Debug)] -pub struct Builder<'a> { - #[allow(dead_code)] - options: Options, +pub struct GraphBuilder<'a> { db: &'a ide_db::RootDatabase, krate: hir::Crate, graph: Graph, @@ -37,14 +33,13 @@ pub struct Builder<'a> { edges: HashMap<(NodeIndex, EdgeKind, NodeIndex), EdgeIndex>, } -impl<'a> Builder<'a> { - pub fn new(options: Options, db: &'a ide_db::RootDatabase, krate: hir::Crate) -> Self { +impl<'a> GraphBuilder<'a> { + pub fn new(db: &'a ide_db::RootDatabase, krate: hir::Crate) -> Self { let graph = Graph::default(); let nodes = HashMap::default(); let edges = HashMap::default(); Self { - options, db, krate, graph, diff --git a/src/command/dependencies/walker.rs b/src/graph/walker.rs similarity index 97% rename from src/command/dependencies/walker.rs rename to src/graph/walker.rs index 5ef723c0..82dbe47a 100644 --- a/src/command/dependencies/walker.rs +++ b/src/graph/walker.rs @@ -6,7 +6,7 @@ use std::collections::HashSet; use petgraph::{graph::NodeIndex, visit::EdgeRef, Direction}; -use super::graph::{Edge, Graph, Node}; +use crate::graph::{Edge, Graph, Node}; pub(crate) struct GraphWalker { direction: Direction, diff --git a/src/lib.rs b/src/lib.rs index 689cd397..368ffbb8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,5 +7,6 @@ pub mod options; pub(crate) mod analyzer; pub(crate) mod colors; +pub(crate) mod graph; pub(crate) mod item; pub(crate) mod tree;