1use crate::domain::CodeFact;
2use std::path::{Path, PathBuf};
3
4#[derive(Debug, Default)]
8pub struct ProjectContext {
9 pub root: PathBuf,
12 pub analysis_root: PathBuf,
15 pub rust_files: Vec<PathBuf>,
16 pub markdown_files: Vec<PathBuf>,
17 pub yaml_files: Vec<PathBuf>,
18 pub makefile_files: Vec<PathBuf>,
19 pub code_facts: Vec<CodeFact>,
20}
21
22impl ProjectContext {
23 pub fn new(root: impl Into<PathBuf>) -> Self {
24 let root = root.into();
25 Self {
26 analysis_root: root.clone(),
27 root,
28 ..Self::default()
29 }
30 }
31
32 pub fn facts_named<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a CodeFact> + 'a {
33 self.code_facts.iter().filter(move |f| f.name == name)
34 }
35
36 pub fn rel<'a>(&self, path: &'a Path) -> &'a Path {
37 path.strip_prefix(&self.analysis_root)
38 .or_else(|_| path.strip_prefix(&self.root))
39 .unwrap_or(path)
40 }
41}