diff options
Diffstat (limited to 'support/texlab/crates/base-db/src/deps/project.rs')
-rw-r--r-- | support/texlab/crates/base-db/src/deps/project.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/support/texlab/crates/base-db/src/deps/project.rs b/support/texlab/crates/base-db/src/deps/project.rs new file mode 100644 index 0000000000..e1b941e67d --- /dev/null +++ b/support/texlab/crates/base-db/src/deps/project.rs @@ -0,0 +1,39 @@ +use itertools::Itertools; +use rustc_hash::FxHashSet; + +use crate::{Document, Workspace}; + +#[derive(Debug, Clone)] +pub struct Project<'a> { + pub documents: FxHashSet<&'a Document>, +} + +impl<'a> Project<'a> { + pub fn from_child(workspace: &'a Workspace, child: &'a Document) -> Self { + let mut documents = FxHashSet::default(); + for graph in workspace.graphs().values() { + if graph.preorder(workspace).contains(&child) { + documents.extend(graph.preorder(workspace)); + } + } + + Self { documents } + } +} + +pub fn parents<'a>(workspace: &'a Workspace, child: &'a Document) -> FxHashSet<&'a Document> { + workspace + .iter() + .filter(|document| { + document + .data + .as_tex() + .map_or(false, |data| data.semantics.can_be_root) + }) + .filter(|parent| { + let graph = &workspace.graphs()[&parent.uri]; + let mut nodes = graph.preorder(workspace); + nodes.contains(&child) + }) + .collect() +} |