diff options
Diffstat (limited to 'support/texlab/src/util')
-rw-r--r-- | support/texlab/src/util/chktex.rs | 2 | ||||
-rw-r--r-- | support/texlab/src/util/cursor.rs | 27 | ||||
-rw-r--r-- | support/texlab/src/util/label.rs | 22 | ||||
-rw-r--r-- | support/texlab/src/util/lang_data.rs | 2 | ||||
-rw-r--r-- | support/texlab/src/util/regex_filter.rs | 12 |
5 files changed, 36 insertions, 29 deletions
diff --git a/support/texlab/src/util/chktex.rs b/support/texlab/src/util/chktex.rs index d87eff5f9c..0774207917 100644 --- a/support/texlab/src/util/chktex.rs +++ b/support/texlab/src/util/chktex.rs @@ -42,7 +42,7 @@ impl Command { log::debug!("Calling ChkTeX from directory: {}", working_dir.display()); - let text = document.contents(db).text(db).clone(); + let text = document.text(db).clone(); Some(Self { text, working_dir }) } diff --git a/support/texlab/src/util/cursor.rs b/support/texlab/src/util/cursor.rs index 63579c433c..d3168155da 100644 --- a/support/texlab/src/util/cursor.rs +++ b/support/texlab/src/util/cursor.rs @@ -24,7 +24,7 @@ impl Cursor { let left = left?; let right = right?; - if left.kind().is_command_name() { + if left.kind() == latex::COMMAND_NAME { return Some(Self::Tex(left)); } @@ -36,7 +36,7 @@ impl Cursor { return Some(Self::Tex(left)); } - if right.kind().is_command_name() { + if right.kind() == latex::COMMAND_NAME { return Some(Self::Tex(right)); } @@ -105,7 +105,7 @@ impl Cursor { pub fn command_range(&self, offset: TextSize) -> Option<TextRange> { self.as_tex() - .filter(|token| token.kind().is_command_name()) + .filter(|token| token.kind() == latex::COMMAND_NAME) .filter(|token| token.text_range().start() != offset) .map(|token| token.text_range()) .map(|range| TextRange::new(range.start() + TextSize::from(1), range.end())) @@ -135,7 +135,7 @@ impl<'db, T> CursorContext<'db, T> { pub fn new(db: &'db dyn Db, uri: &Url, position: Position, params: T) -> Option<Self> { let workspace = Workspace::get(db); let document = workspace.lookup_uri(db, uri)?; - let line_index = document.contents(db).line_index(db); + let line_index = document.line_index(db); let offset = line_index.offset_lsp(position); let cursor = match document.parse(db) { @@ -251,6 +251,22 @@ impl<'db, T> CursorContext<'db, T> { Some((name, range)) } + pub fn find_environment(&self) -> Option<(latex::Key, latex::Key)> { + let token = self.cursor.as_tex()?; + + for env in token + .parent_ancestors() + .filter_map(latex::Environment::cast) + { + let beg = env.begin()?.name()?.key()?; + let end = env.end()?.name()?.key()?; + + return Some((beg, end)); + } + + None + } + pub fn find_curly_group_word(&self) -> Option<(String, TextRange, latex::CurlyGroupWord)> { let token = self.cursor.as_tex()?; let key = latex::Key::cast(token.parent()?); @@ -285,8 +301,7 @@ impl<'db, T> CursorContext<'db, T> { let range = if group .syntax() .last_token() - .filter(|tok| tok.kind() == latex::MISSING) - .is_some() + .map_or(false, |tok| tok.kind() != latex::R_CURLY) { TextRange::new(latex::small_range(&key).start(), token.text_range().end()) } else { diff --git a/support/texlab/src/util/label.rs b/support/texlab/src/util/label.rs index 50e2ea21e7..74c72b234a 100644 --- a/support/texlab/src/util/label.rs +++ b/support/texlab/src/util/label.rs @@ -10,8 +10,6 @@ use crate::{ use self::LabeledObject::*; -use super::lang_data::LANGUAGE_DATA; - #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum LabeledFloatKind { Figure, @@ -135,7 +133,7 @@ pub fn render(db: &dyn Db, document: Document, label_def: label::Name) -> Option render_label_float(parent.clone(), label_num) .or_else(|| render_label_section(parent.clone(), label_num)) .or_else(|| render_label_enum_item(db, parent.clone(), label_num)) - .or_else(|| render_label_equation(parent.clone(), label_num)) + .or_else(|| render_label_equation(db, parent.clone(), label_num)) .or_else(|| render_label_theorem(db, document, parent, label_num)) }) } @@ -214,20 +212,20 @@ fn render_label_enum_item( }) } -fn render_label_equation(parent: latex::SyntaxNode, number: Option<Word>) -> Option<RenderedLabel> { - let environment = latex::Environment::cast(parent)?; - let environment_name = environment.begin()?.name()?.key()?.to_string(); +fn render_label_equation( + db: &dyn Db, + parent: latex::SyntaxNode, + number: Option<Word>, +) -> Option<RenderedLabel> { + let env = latex::Environment::cast(parent)?; + let env_name = env.begin()?.name()?.key()?.to_string(); - if !LANGUAGE_DATA - .math_environments - .iter() - .any(|name| name == &environment_name) - { + if !db.config().syntax.math_environments.contains(&env_name) { return None; } Some(RenderedLabel { - range: latex::small_range(&environment), + range: latex::small_range(&env), number, object: LabeledObject::Equation, }) diff --git a/support/texlab/src/util/lang_data.rs b/support/texlab/src/util/lang_data.rs index f270c3f65e..734ceb6df2 100644 --- a/support/texlab/src/util/lang_data.rs +++ b/support/texlab/src/util/lang_data.rs @@ -36,8 +36,6 @@ pub struct LanguageData { pub fields: Vec<BibtexFieldDoc>, pub pgf_libraries: Vec<String>, pub tikz_libraries: Vec<String>, - pub math_environments: Vec<String>, - pub enum_environments: Vec<String>, } impl LanguageData { diff --git a/support/texlab/src/util/regex_filter.rs b/support/texlab/src/util/regex_filter.rs index f107ea16fe..a33417464e 100644 --- a/support/texlab/src/util/regex_filter.rs +++ b/support/texlab/src/util/regex_filter.rs @@ -1,21 +1,17 @@ -use crate::RegexPattern; +use regex::Regex; -pub fn filter( - text: &str, - allowed_patterns: &[RegexPattern], - ignored_patterns: &[RegexPattern], -) -> bool { +pub fn filter(text: &str, allowed_patterns: &[Regex], ignored_patterns: &[Regex]) -> bool { if !allowed_patterns.is_empty() && !allowed_patterns .iter() - .any(|pattern| pattern.0.is_match(text)) + .any(|pattern| pattern.is_match(text)) { return false; } if ignored_patterns .iter() - .any(|pattern| pattern.0.is_match(text)) + .any(|pattern| pattern.is_match(text)) { return false; } |