blob: e1b941e67db40dee24fd585ae0c2ad4b1e4a97b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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()
}
|