summaryrefslogtreecommitdiff
path: root/support/texlab/src/db/parse.rs
blob: 7187135d520014cf49cb5f3d8bf33cdd266ab2c2 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use crate::{
    db::analysis::TexAnalysis,
    syntax::{bibtex, latex, BuildLog},
    Db,
};

#[salsa::interned]
pub struct TexDocumentData {
    pub green: rowan::GreenNode,
}

impl TexDocumentData {
    pub fn root(self, db: &dyn Db) -> latex::SyntaxNode {
        latex::SyntaxNode::new_root(self.green(db))
    }
}

#[salsa::tracked]
impl TexDocumentData {
    #[salsa::tracked]
    pub fn analyze(self, db: &dyn Db) -> TexAnalysis {
        let root = latex::SyntaxNode::new_root(self.green(db));
        TexAnalysis::analyze(db, &root)
    }
}

#[salsa::interned]
pub struct BibDocumentData {
    pub green: rowan::GreenNode,
}

impl BibDocumentData {
    pub fn root(self, db: &dyn Db) -> bibtex::SyntaxNode {
        bibtex::SyntaxNode::new_root(self.green(db))
    }
}

#[salsa::interned]
pub struct LogDocumentData {
    pub log: BuildLog,
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
pub struct TexlabRootData;

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
pub struct TectonicData;

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
pub enum DocumentData {
    Tex(TexDocumentData),
    Bib(BibDocumentData),
    Log(LogDocumentData),
    TexlabRoot(TexlabRootData),
    Tectonic(TectonicData),
}

impl DocumentData {
    pub fn as_tex(self) -> Option<TexDocumentData> {
        match self {
            Self::Tex(data) => Some(data),
            _ => None,
        }
    }

    pub fn as_bib(self) -> Option<BibDocumentData> {
        match self {
            Self::Bib(data) => Some(data),
            _ => None,
        }
    }

    pub fn as_log(self) -> Option<LogDocumentData> {
        match self {
            Self::Log(data) => Some(data),
            _ => None,
        }
    }
}