summaryrefslogtreecommitdiff
path: root/support/texlab/src/symbol/latex_section/equation.rs
blob: 4c2fcbe295fccf880a7b4e8b1a4f30979bef6007 (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
use super::{label_name, selection_range};
use crate::symbol::{LatexSymbol, LatexSymbolKind};
use crate::syntax::*;
use crate::workspace::*;
use lsp_types::Range;

pub fn symbols(view: &DocumentView, tree: &LatexSyntaxTree) -> Vec<LatexSymbol> {
    let mut symbols = Vec::new();
    for equation in &tree.math.equations {
        symbols.push(make_symbol(view, tree, equation.range()));
    }

    for equation in &tree.env.environments {
        if equation.left.is_math() {
            symbols.push(make_symbol(view, tree, equation.range()));
        }
    }
    symbols
}

fn make_symbol(view: &DocumentView, tree: &LatexSyntaxTree, full_range: Range) -> LatexSymbol {
    let label = tree.find_label_by_range(full_range);

    let name = match label
        .as_ref()
        .and_then(|label| OutlineContext::find_number(view, label))
    {
        Some(num) => format!("Equation ({})", num),
        None => "Equation".to_owned(),
    };

    LatexSymbol {
        name,
        label: label_name(label),
        kind: LatexSymbolKind::Equation,
        deprecated: false,
        full_range,
        selection_range: selection_range(full_range, label),
        children: Vec::new(),
    }
}