diff options
Diffstat (limited to 'support/texlab/src/db/diagnostics/tex.rs')
-rw-r--r-- | support/texlab/src/db/diagnostics/tex.rs | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/support/texlab/src/db/diagnostics/tex.rs b/support/texlab/src/db/diagnostics/tex.rs index 50233f8bd6..a7b030a5bf 100644 --- a/support/texlab/src/db/diagnostics/tex.rs +++ b/support/texlab/src/db/diagnostics/tex.rs @@ -5,7 +5,7 @@ use crate::{db::document::Document, syntax::latex, util::line_index_ext::LineInd use super::{Diagnostic, DiagnosticCode, TexCode}; -#[salsa::tracked(return_ref)] +#[salsa::tracked] pub fn collect(db: &dyn Db, document: Document) -> Vec<Diagnostic> { let mut results = Vec::new(); @@ -18,10 +18,35 @@ pub fn collect(db: &dyn Db, document: Document) -> Vec<Diagnostic> { None => return results, }; - for node in data.root(db).descendants() { - analyze_environment(db, document, node.clone(), &mut results) - .or_else(|| analyze_curly_group(db, document, node.clone(), &mut results)) - .or_else(|| analyze_curly_braces(document, db, node, &mut results)); + let mut traversal = data.root(db).preorder(); + while let Some(event) = traversal.next() { + match event { + rowan::WalkEvent::Enter(node) => { + if let Some(environment) = latex::Environment::cast(node.clone()) { + if environment + .begin() + .and_then(|begin| begin.name()) + .and_then(|name| name.key()) + .map_or(false, |name| { + db.config() + .syntax + .verbatim_environments + .contains(&name.to_string()) + }) + { + traversal.skip_subtree(); + continue; + } + } + + analyze_environment(db, document, node.clone(), &mut results) + .or_else(|| analyze_curly_group(db, document, node.clone(), &mut results)) + .or_else(|| analyze_curly_braces(document, db, node, &mut results)); + } + rowan::WalkEvent::Leave(_) => { + continue; + } + }; } results @@ -41,7 +66,6 @@ fn analyze_environment( results.push(Diagnostic { severity: DiagnosticSeverity::ERROR, range: document - .contents(db) .line_index(db) .line_col_lsp_range(latex::small_range(&name1)), code: DiagnosticCode::Tex(code), @@ -89,7 +113,6 @@ fn analyze_curly_group( results.push(Diagnostic { severity: DiagnosticSeverity::ERROR, range: document - .contents(db) .line_index(db) .line_col_lsp_range(TextRange::empty(node.text_range().end())), code: DiagnosticCode::Tex(code), @@ -111,7 +134,6 @@ fn analyze_curly_braces( results.push(Diagnostic { severity: DiagnosticSeverity::ERROR, range: document - .contents(db) .line_index(db) .line_col_lsp_range(node.text_range()), code: DiagnosticCode::Tex(code), |