diff options
author | Norbert Preining <norbert@preining.info> | 2024-03-17 03:01:42 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2024-03-17 03:01:42 +0000 |
commit | 55140d5421e1ad0024c9acbfa72bd06402c2aa9f (patch) | |
tree | b6c0d76888f025b58f1221d8dadbefb0264e9f6c /support/texlab/crates/diagnostics | |
parent | 966f9ba332e49c29e961cb86e08f97d70eda51f6 (diff) |
CTAN sync 202403170301
Diffstat (limited to 'support/texlab/crates/diagnostics')
-rw-r--r-- | support/texlab/crates/diagnostics/Cargo.toml | 4 | ||||
-rw-r--r-- | support/texlab/crates/diagnostics/src/citations.rs | 24 | ||||
-rw-r--r-- | support/texlab/crates/diagnostics/src/labels.rs | 25 | ||||
-rw-r--r-- | support/texlab/crates/diagnostics/src/manager.rs | 43 | ||||
-rw-r--r-- | support/texlab/crates/diagnostics/src/tests.rs | 2 |
5 files changed, 74 insertions, 24 deletions
diff --git a/support/texlab/crates/diagnostics/Cargo.toml b/support/texlab/crates/diagnostics/Cargo.toml index 1fb4b2171d..91c2ff9dbd 100644 --- a/support/texlab/crates/diagnostics/Cargo.toml +++ b/support/texlab/crates/diagnostics/Cargo.toml @@ -14,8 +14,8 @@ encoding_rs = "0.8.33" encoding_rs_io = "0.1.7" itertools = "0.12.0" line-index = { path = "../line-index" } -log = "0.4.20" -multimap = "0.9.1" +log = "0.4.21" +multimap = "0.10.0" once_cell = "1.19.0" parking_lot = "0.12.1" regex = "1.10.2" diff --git a/support/texlab/crates/diagnostics/src/citations.rs b/support/texlab/crates/diagnostics/src/citations.rs index 403d2f5bfc..ea4ef03d58 100644 --- a/support/texlab/crates/diagnostics/src/citations.rs +++ b/support/texlab/crates/diagnostics/src/citations.rs @@ -3,8 +3,7 @@ use base_db::{ util::queries::{self, Object}, Document, Project, Workspace, }; -use multimap::MultiMap; -use rustc_hash::FxHashSet; +use rustc_hash::{FxHashMap, FxHashSet}; use url::Url; use crate::types::{BibError, Diagnostic, TexError}; @@ -14,7 +13,7 @@ const MAX_UNUSED_ENTRIES: usize = 1000; pub fn detect_undefined_citations<'a>( project: &Project<'a>, document: &'a Document, - results: &mut MultiMap<Url, Diagnostic>, + results: &mut FxHashMap<Url, Vec<Diagnostic>>, ) -> Option<()> { let data = document.data.as_tex()?; @@ -26,7 +25,10 @@ pub fn detect_undefined_citations<'a>( let name = citation.name_text(); if name != "*" && !entries.contains(name) { let diagnostic = Diagnostic::Tex(citation.name.range, TexError::UndefinedCitation); - results.insert(document.uri.clone(), diagnostic); + results + .entry(document.uri.clone()) + .or_default() + .push(diagnostic); } } @@ -36,7 +38,7 @@ pub fn detect_undefined_citations<'a>( pub fn detect_unused_entries<'a>( project: &Project<'a>, document: &'a Document, - results: &mut MultiMap<Url, Diagnostic>, + results: &mut FxHashMap<Url, Vec<Diagnostic>>, ) -> Option<()> { let data = document.data.as_bib()?; @@ -52,7 +54,10 @@ pub fn detect_unused_entries<'a>( for entry in &data.semantics.entries { if !citations.contains(entry.name.text.as_str()) { let diagnostic = Diagnostic::Bib(entry.name.range, BibError::UnusedEntry); - results.insert(document.uri.clone(), diagnostic); + results + .entry(document.uri.clone()) + .or_default() + .push(diagnostic); } } @@ -61,7 +66,7 @@ pub fn detect_unused_entries<'a>( pub fn detect_duplicate_entries<'a>( workspace: &'a Workspace, - results: &mut MultiMap<Url, Diagnostic>, + results: &mut FxHashMap<Url, Vec<Diagnostic>>, ) { for conflict in queries::Conflict::find_all::<Entry>(workspace) { let others = conflict @@ -71,6 +76,9 @@ pub fn detect_duplicate_entries<'a>( .collect(); let diagnostic = Diagnostic::Bib(conflict.main.range, BibError::DuplicateEntry(others)); - results.insert(conflict.main.document.uri.clone(), diagnostic); + results + .entry(conflict.main.document.uri.clone()) + .or_default() + .push(diagnostic); } } diff --git a/support/texlab/crates/diagnostics/src/labels.rs b/support/texlab/crates/diagnostics/src/labels.rs index 92f9072918..9a39f3f24b 100644 --- a/support/texlab/crates/diagnostics/src/labels.rs +++ b/support/texlab/crates/diagnostics/src/labels.rs @@ -4,15 +4,14 @@ use base_db::{ DocumentData, Workspace, }; use itertools::Itertools; -use multimap::MultiMap; -use rustc_hash::FxHashSet; +use rustc_hash::{FxHashMap, FxHashSet}; use url::Url; use crate::types::{Diagnostic, TexError}; pub fn detect_undefined_and_unused_labels( workspace: &Workspace, - results: &mut MultiMap<Url, Diagnostic>, + results: &mut FxHashMap<Url, Vec<Diagnostic>>, ) { let graphs: Vec<_> = workspace .iter() @@ -45,18 +44,27 @@ pub fn detect_undefined_and_unused_labels( for label in &data.semantics.labels { if label.kind != LabelKind::Definition && !label_defs.contains(&label.name.text) { let diagnostic = Diagnostic::Tex(label.name.range, TexError::UndefinedLabel); - results.insert(document.uri.clone(), diagnostic); + results + .entry(document.uri.clone()) + .or_default() + .push(diagnostic); } if label.kind == LabelKind::Definition && !label_refs.contains(&label.name.text) { let diagnostic = Diagnostic::Tex(label.name.range, TexError::UnusedLabel); - results.insert(document.uri.clone(), diagnostic); + results + .entry(document.uri.clone()) + .or_default() + .push(diagnostic); } } } } -pub fn detect_duplicate_labels(workspace: &Workspace, results: &mut MultiMap<Url, Diagnostic>) { +pub fn detect_duplicate_labels( + workspace: &Workspace, + results: &mut FxHashMap<Url, Vec<Diagnostic>>, +) { for conflict in queries::Conflict::find_all::<Label>(workspace) { let others = conflict .rest @@ -65,6 +73,9 @@ pub fn detect_duplicate_labels(workspace: &Workspace, results: &mut MultiMap<Url .collect(); let diagnostic = Diagnostic::Tex(conflict.main.range, TexError::DuplicateLabel(others)); - results.insert(conflict.main.document.uri.clone(), diagnostic); + results + .entry(conflict.main.document.uri.clone()) + .or_default() + .push(diagnostic); } } diff --git a/support/texlab/crates/diagnostics/src/manager.rs b/support/texlab/crates/diagnostics/src/manager.rs index 1ce5e194b8..38c0a514f4 100644 --- a/support/texlab/crates/diagnostics/src/manager.rs +++ b/support/texlab/crates/diagnostics/src/manager.rs @@ -16,6 +16,10 @@ pub struct Manager { impl Manager { /// Updates the syntax-based diagnostics for the given document. pub fn update_syntax(&mut self, workspace: &Workspace, document: &Document) { + if !Self::is_relevant(document) { + return; + } + self.grammar.remove(&document.uri); super::grammar::tex::update(document, workspace.config(), &mut self.grammar); super::grammar::bib::update(document, &mut self.grammar); @@ -30,14 +34,20 @@ impl Manager { } /// Returns all filtered diagnostics for the given workspace. - pub fn get(&self, workspace: &Workspace) -> MultiMap<Url, Diagnostic> { - let mut results = MultiMap::default(); + pub fn get(&self, workspace: &Workspace) -> FxHashMap<Url, Vec<Diagnostic>> { + let mut results: FxHashMap<Url, Vec<Diagnostic>> = FxHashMap::default(); for (uri, diagnostics) in &self.grammar { - results.insert_many_from_slice(uri.clone(), diagnostics); + results + .entry(uri.clone()) + .or_default() + .extend(diagnostics.iter().cloned()); } for (uri, diagnostics) in self.build_log.values().flatten() { - results.insert_many_from_slice(uri.clone(), diagnostics); + results + .entry(uri.clone()) + .or_default() + .extend(diagnostics.iter().cloned()); } for (uri, diagnostics) in &self.chktex { @@ -45,11 +55,17 @@ impl Manager { .lookup(uri) .map_or(false, |document| document.owner == Owner::Client) { - results.insert_many_from_slice(uri.clone(), diagnostics); + results + .entry(uri.clone()) + .or_default() + .extend(diagnostics.iter().cloned()); } } - for document in workspace.iter() { + for document in workspace + .iter() + .filter(|document| Self::is_relevant(document)) + { let project = workspace.project(document); super::citations::detect_undefined_citations(&project, document, &mut results); super::citations::detect_unused_entries(&project, document, &mut results); @@ -60,6 +76,13 @@ impl Manager { super::labels::detect_undefined_and_unused_labels(workspace, &mut results); let config = &workspace.config().diagnostics; + + results.retain(|uri, _| { + workspace + .lookup(uri) + .map_or(false, |document| Self::is_relevant(document)) + }); + for (_, diagnostics) in &mut results { diagnostics.retain(|diagnostic| { filter_regex_patterns( @@ -72,4 +95,12 @@ impl Manager { results } + + fn is_relevant(document: &Document) -> bool { + match document.owner { + Owner::Client => true, + Owner::Server => true, + Owner::Distro => false, + } + } } diff --git a/support/texlab/crates/diagnostics/src/tests.rs b/support/texlab/crates/diagnostics/src/tests.rs index b7c6004d19..3688abeaf4 100644 --- a/support/texlab/crates/diagnostics/src/tests.rs +++ b/support/texlab/crates/diagnostics/src/tests.rs @@ -11,7 +11,7 @@ fn check(input: &str, expect: Expect) { let results = manager.get(&fixture.workspace); let results = results - .iter_all() + .iter() .filter(|(_, diags)| !diags.is_empty()) .sorted_by(|(uri1, _), (uri2, _)| uri1.cmp(&uri2)) .map(|(uri, diags)| (uri.as_str(), diags)) |