use std::{mem, sync::Arc};
-use ra_ide::FileId;
+use ide::FileId;
use rustc_hash::{FxHashMap, FxHashSet};
use crate::lsp_ext;
pub(crate) type CheckFixes = Arc<FxHashMap<FileId, Vec<Fix>>>;
#[derive(Debug, Default, Clone)]
-pub struct DiagnosticsConfig {
+pub struct DiagnosticsMapConfig {
+ pub remap_prefix: FxHashMap<String, String>,
pub warnings_as_info: Vec<String>,
pub warnings_as_hint: Vec<String>,
}
#[derive(Debug, Clone)]
pub(crate) struct Fix {
- pub(crate) range: lsp_types::Range,
+ // Fixes may be triggerable from multiple ranges.
+ pub(crate) ranges: Vec<lsp_types::Range>,
pub(crate) action: lsp_ext::CodeAction,
}
&mut self,
file_id: FileId,
diagnostic: lsp_types::Diagnostic,
- fixes: Vec<lsp_ext::CodeAction>,
+ fix: Option<Fix>,
) {
let diagnostics = self.check.entry(file_id).or_default();
for existing_diagnostic in diagnostics.iter() {
- if are_diagnostics_equal(&existing_diagnostic, &diagnostic) {
+ if are_diagnostics_equal(existing_diagnostic, &diagnostic) {
return;
}
}
let check_fixes = Arc::make_mut(&mut self.check_fixes);
- check_fixes
- .entry(file_id)
- .or_default()
- .extend(fixes.into_iter().map(|action| Fix { range: diagnostic.range, action }));
+ check_fixes.entry(file_id).or_default().extend(fix);
diagnostics.push(diagnostic);
self.changes.insert(file_id);
}
file_id: FileId,
diagnostics: Vec<lsp_types::Diagnostic>,
) {
+ if let Some(existing_diagnostics) = self.native.get(&file_id) {
+ if existing_diagnostics.len() == diagnostics.len()
+ && diagnostics
+ .iter()
+ .zip(existing_diagnostics)
+ .all(|(new, existing)| are_diagnostics_equal(new, existing))
+ {
+ return;
+ }
+ }
+
self.native.insert(file_id, diagnostics);
self.changes.insert(file_id);
}