summaryrefslogtreecommitdiff
path: root/support/texlab/crates/base-db/src/semantics/auxiliary.rs
diff options
context:
space:
mode:
Diffstat (limited to 'support/texlab/crates/base-db/src/semantics/auxiliary.rs')
-rw-r--r--support/texlab/crates/base-db/src/semantics/auxiliary.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/support/texlab/crates/base-db/src/semantics/auxiliary.rs b/support/texlab/crates/base-db/src/semantics/auxiliary.rs
index 8c9fe012e6..bb9a2c065c 100644
--- a/support/texlab/crates/base-db/src/semantics/auxiliary.rs
+++ b/support/texlab/crates/base-db/src/semantics/auxiliary.rs
@@ -5,6 +5,7 @@ use syntax::latex::{self, HasCurly};
#[derive(Debug, Clone, Default)]
pub struct Semantics {
pub label_numbers: FxHashMap<String, String>,
+ pub section_numbers: FxHashMap<String, String>,
}
impl Semantics {
@@ -18,6 +19,9 @@ impl Semantics {
if let Some(label_number) = latex::LabelNumber::cast(node.clone()) {
self.process_label_number(&label_number);
}
+ if let Some(toc_line) = latex::TocContentsLine::cast(node.clone()) {
+ self.process_toc_line(&toc_line);
+ }
}
fn process_label_number(&mut self, label_number: &latex::LabelNumber) -> Option<()> {
@@ -40,4 +44,36 @@ impl Semantics {
self.label_numbers.insert(name, text);
Some(())
}
+
+ fn process_toc_line(&mut self, toc_line: &latex::TocContentsLine) -> Option<()> {
+ let unit = toc_line.unit().and_then(|u| u.content_text())?.to_string();
+
+ if [
+ "part",
+ "chapter",
+ "section",
+ "subsection",
+ "subsubsection",
+ "paragraph",
+ "subparagraph",
+ ]
+ .contains(&unit.as_str())
+ {
+ let line = toc_line.line()?;
+ let name = line.syntax().children().find_map(|child| {
+ latex::Text::cast(child.clone())?;
+ Some(child)
+ })?;
+ let name = name.to_string();
+
+ let num_line = line
+ .syntax()
+ .children()
+ .find_map(|child| latex::TocNumberLine::cast(child.clone()))?;
+ let number = num_line.number()?;
+ let number = number.content_text()?.replace(['{', '}'], "");
+ self.section_numbers.insert(name, number);
+ }
+ Some(())
+ }
}