summaryrefslogtreecommitdiff
path: root/support/texlab/src/syntax/latex/analysis/types.rs
blob: f089721397fc4b2ae4b39f073ea39890558cb2f9 (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
use std::sync::Arc;

use cstree::TextRange;
use rustc_hash::{FxHashMap, FxHashSet};
use smol_str::SmolStr;

use crate::{ServerContext, Uri};

#[derive(Debug)]
pub struct LatexAnalyzerContext {
    pub inner: Arc<ServerContext>,
    pub document_uri: Arc<Uri>,
    pub base_uri: Arc<Uri>,
    pub extras: Extras,
}

#[derive(Debug, Clone, Default)]
pub struct Extras {
    pub implicit_links: ImplicitLinks,
    pub explicit_links: Vec<ExplicitLink>,
    pub has_document_environment: bool,
    pub command_names: FxHashSet<SmolStr>,
    pub environment_names: FxHashSet<SmolStr>,
    pub label_names: Vec<LabelName>,
    pub label_numbers_by_name: FxHashMap<SmolStr, String>,
    pub theorem_environments: Vec<TheoremEnvironment>,
}

#[derive(Debug, PartialEq, Eq, Clone, Default, Hash)]
pub struct ImplicitLinks {
    pub aux: Vec<Arc<Uri>>,
    pub log: Vec<Arc<Uri>>,
    pub pdf: Vec<Arc<Uri>>,
}

#[derive(Debug, PartialEq, Eq, Clone, Copy, PartialOrd, Ord, Hash)]
pub enum ExplicitLinkKind {
    Package,
    Class,
    Latex,
    Bibtex,
}

#[derive(Debug, Clone)]
pub struct ExplicitLink {
    pub stem: SmolStr,
    pub stem_range: TextRange,
    pub targets: Vec<Arc<Uri>>,
    pub kind: ExplicitLinkKind,
}

impl ExplicitLink {
    pub fn as_component_name(&self) -> Option<String> {
        match self.kind {
            ExplicitLinkKind::Package => Some(format!("{}.sty", self.stem)),
            ExplicitLinkKind::Class => Some(format!("{}.cls", self.stem)),
            ExplicitLinkKind::Latex | ExplicitLinkKind::Bibtex => None,
        }
    }
}

#[derive(Debug, PartialEq, Eq, Clone, Default, Hash)]
pub struct TheoremEnvironment {
    pub name: SmolStr,
    pub description: String,
}

#[derive(Debug, PartialEq, Eq, Clone, Default, Hash)]
pub struct LabelName {
    pub text: SmolStr,
    pub range: TextRange,
    pub is_definition: bool,
}