diff options
author | Norbert Preining <norbert@preining.info> | 2019-12-03 03:01:24 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-12-03 03:01:24 +0000 |
commit | b8d4bb76703bcb15578e2b23c5d256532180b894 (patch) | |
tree | bedd1df7a00521a2bd986b3c0289d6556a59e39b /support/texlab/src/symbol/latex_section/equation.rs | |
parent | 02e4625a78a5029e8b5dc2a4ec70193b232f497e (diff) |
CTAN sync 201912030301
Diffstat (limited to 'support/texlab/src/symbol/latex_section/equation.rs')
-rw-r--r-- | support/texlab/src/symbol/latex_section/equation.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/support/texlab/src/symbol/latex_section/equation.rs b/support/texlab/src/symbol/latex_section/equation.rs new file mode 100644 index 0000000000..4c2fcbe295 --- /dev/null +++ b/support/texlab/src/symbol/latex_section/equation.rs @@ -0,0 +1,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(), + } +} |