Skip to content

Commit

Permalink
Extract modules `crate::command::dependencies::{graph,builder,walker}…
Browse files Browse the repository at this point in the history
…` to `crate::graph`
  • Loading branch information
regexident committed Dec 13, 2023
1 parent 90fdb23 commit fa75ab9
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 27 deletions.
3 changes: 0 additions & 3 deletions src/command/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
9 changes: 5 additions & 4 deletions src/command/dependencies/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/command/dependencies/cycles/tri_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
vec: BitVec,
Expand Down
11 changes: 5 additions & 6 deletions src/command/dependencies/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions src/command/dependencies/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down
5 changes: 5 additions & 0 deletions src/command/dependencies/graph.rs → src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node, Edge>;

#[derive(Clone, PartialEq, Debug)]
Expand Down
15 changes: 5 additions & 10 deletions src/command/dependencies/builder.rs → src/graph/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -27,24 +25,21 @@ 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,
nodes: HashMap<hir::ModuleDef, NodeIndex>,
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,
Expand Down
2 changes: 1 addition & 1 deletion src/command/dependencies/walker.rs → src/graph/walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit fa75ab9

Please sign in to comment.