diff options
Diffstat (limited to 'support/texlab/crates/diagnostics/src/labels.rs')
-rw-r--r-- | support/texlab/crates/diagnostics/src/labels.rs | 53 |
1 files changed, 13 insertions, 40 deletions
diff --git a/support/texlab/crates/diagnostics/src/labels.rs b/support/texlab/crates/diagnostics/src/labels.rs index 03df664a15..92f9072918 100644 --- a/support/texlab/crates/diagnostics/src/labels.rs +++ b/support/texlab/crates/diagnostics/src/labels.rs @@ -1,35 +1,18 @@ -use std::borrow::Cow; - use base_db::{ semantics::tex::{Label, LabelKind}, util::queries, DocumentData, Workspace, }; use itertools::Itertools; +use multimap::MultiMap; use rustc_hash::FxHashSet; +use url::Url; -use crate::{ - types::{DiagnosticData, TexError}, - Diagnostic, DiagnosticBuilder, DiagnosticSource, -}; - -#[derive(Default)] -pub struct LabelErrors; - -impl DiagnosticSource for LabelErrors { - fn publish<'db>( - &'db mut self, - workspace: &'db Workspace, - builder: &mut DiagnosticBuilder<'db>, - ) { - detect_undefined_and_unused_labels(workspace, builder); - detect_duplicate_labels(workspace, builder); - } -} +use crate::types::{Diagnostic, TexError}; -fn detect_undefined_and_unused_labels<'db>( - workspace: &'db Workspace, - builder: &mut DiagnosticBuilder<'db>, +pub fn detect_undefined_and_unused_labels( + workspace: &Workspace, + results: &mut MultiMap<Url, Diagnostic>, ) { let graphs: Vec<_> = workspace .iter() @@ -61,25 +44,19 @@ fn detect_undefined_and_unused_labels<'db>( for label in &data.semantics.labels { if label.kind != LabelKind::Definition && !label_defs.contains(&label.name.text) { - let diagnostic = Diagnostic { - range: label.name.range, - data: DiagnosticData::Tex(TexError::UndefinedLabel), - }; - builder.push(&document.uri, Cow::Owned(diagnostic)); + let diagnostic = Diagnostic::Tex(label.name.range, TexError::UndefinedLabel); + results.insert(document.uri.clone(), diagnostic); } if label.kind == LabelKind::Definition && !label_refs.contains(&label.name.text) { - let diagnostic = Diagnostic { - range: label.name.range, - data: DiagnosticData::Tex(TexError::UnusedLabel), - }; - builder.push(&document.uri, Cow::Owned(diagnostic)); + let diagnostic = Diagnostic::Tex(label.name.range, TexError::UnusedLabel); + results.insert(document.uri.clone(), diagnostic); } } } } -fn detect_duplicate_labels<'db>(workspace: &'db Workspace, builder: &mut DiagnosticBuilder<'db>) { +pub fn detect_duplicate_labels(workspace: &Workspace, results: &mut MultiMap<Url, Diagnostic>) { for conflict in queries::Conflict::find_all::<Label>(workspace) { let others = conflict .rest @@ -87,11 +64,7 @@ fn detect_duplicate_labels<'db>(workspace: &'db Workspace, builder: &mut Diagnos .map(|location| (location.document.uri.clone(), location.range)) .collect(); - let diagnostic = Diagnostic { - range: conflict.main.range, - data: DiagnosticData::Tex(TexError::DuplicateLabel(others)), - }; - - builder.push(&conflict.main.document.uri, Cow::Owned(diagnostic)); + let diagnostic = Diagnostic::Tex(conflict.main.range, TexError::DuplicateLabel(others)); + results.insert(conflict.main.document.uri.clone(), diagnostic); } } |