texlab/syntax/latex/analysis/
types.rs1use std::sync::Arc;
2
3use lsp_types::Url;
4use rowan::TextRange;
5use rustc_hash::{FxHashMap, FxHashSet};
6use smol_str::SmolStr;
7
8use crate::Environment;
9
10#[derive(Debug)]
11pub struct LatexAnalyzerContext<'a> {
12 pub environment: &'a Environment,
13 pub document_uri: Arc<Url>,
14 pub base_uri: Arc<Url>,
15 pub extras: Extras,
16}
17
18#[derive(Debug, Clone, Default)]
19pub struct Extras {
20 pub implicit_links: ImplicitLinks,
21 pub explicit_links: Vec<ExplicitLink>,
22 pub has_document_environment: bool,
23 pub command_names: FxHashSet<SmolStr>,
24 pub environment_names: FxHashSet<String>,
25 pub label_names: Vec<LabelName>,
26 pub label_numbers_by_name: FxHashMap<String, String>,
27 pub theorem_environments: Vec<TheoremEnvironment>,
28 pub graphics_paths: FxHashSet<String>,
29}
30
31#[derive(Debug, PartialEq, Eq, Clone, Default, Hash)]
32pub struct ImplicitLinks {
33 pub aux: Vec<Arc<Url>>,
34 pub log: Vec<Arc<Url>>,
35 pub pdf: Vec<Arc<Url>>,
36}
37
38#[derive(Debug, PartialEq, Eq, Clone, Copy, PartialOrd, Ord, Hash)]
39pub enum ExplicitLinkKind {
40 Package,
41 Class,
42 Latex,
43 Bibtex,
44}
45
46#[derive(Debug, Clone)]
47pub struct ExplicitLink {
48 pub stem: SmolStr,
49 pub stem_range: TextRange,
50 pub targets: Vec<Arc<Url>>,
51 pub kind: ExplicitLinkKind,
52}
53
54impl ExplicitLink {
55 pub fn as_component_name(&self) -> Option<String> {
56 match self.kind {
57 ExplicitLinkKind::Package => Some(format!("{}.sty", self.stem)),
58 ExplicitLinkKind::Class => Some(format!("{}.cls", self.stem)),
59 ExplicitLinkKind::Latex | ExplicitLinkKind::Bibtex => None,
60 }
61 }
62}
63
64#[derive(Debug, PartialEq, Eq, Clone, Default, Hash)]
65pub struct TheoremEnvironment {
66 pub name: String,
67 pub description: String,
68}
69
70#[derive(Debug, PartialEq, Eq, Clone, Default, Hash)]
71pub struct LabelName {
72 pub text: SmolStr,
73 pub range: TextRange,
74 pub is_definition: bool,
75}