Fix diagnostic unit test

This commit is contained in:
Antonio Scandurra 2021-12-10 09:43:21 +01:00
parent eeba0993aa
commit cb97b7cd1d
2 changed files with 14 additions and 14 deletions

View file

@ -23,7 +23,6 @@ use std::{
ffi::OsString, ffi::OsString,
future::Future, future::Future,
iter::{Iterator, Peekable}, iter::{Iterator, Peekable},
mem,
ops::{Deref, DerefMut, Range}, ops::{Deref, DerefMut, Range},
path::{Path, PathBuf}, path::{Path, PathBuf},
str, str,
@ -794,8 +793,7 @@ impl Buffer {
} }
drop(edits_since_save); drop(edits_since_save);
let mut diagnostics = mem::take(&mut self.diagnostics); let new_diagnostics = DiagnosticSet::new(
diagnostics.reset(
diagnostics_by_group_id diagnostics_by_group_id
.into_values() .into_values()
.flat_map(|mut diagnostics| { .flat_map(|mut diagnostics| {
@ -806,9 +804,9 @@ impl Buffer {
primary.diagnostic.is_primary = true; primary.diagnostic.is_primary = true;
diagnostics diagnostics
}), }),
self, content,
); );
self.diagnostics = diagnostics; self.diagnostics = new_diagnostics;
if let Some(version) = version { if let Some(version) = version {
let language_server = self.language_server.as_mut().unwrap(); let language_server = self.language_server.as_mut().unwrap();

View file

@ -37,20 +37,22 @@ impl DiagnosticSet {
} }
} }
pub fn reset<I>(&mut self, iter: I, buffer: &text::Snapshot) pub fn new<I>(iter: I, buffer: &text::Snapshot) -> Self
where where
I: IntoIterator<Item = DiagnosticEntry<PointUtf16>>, I: IntoIterator<Item = DiagnosticEntry<PointUtf16>>,
{ {
let mut entries = iter.into_iter().collect::<Vec<_>>(); let mut entries = iter.into_iter().collect::<Vec<_>>();
entries.sort_unstable_by_key(|entry| (entry.range.start, Reverse(entry.range.end))); entries.sort_unstable_by_key(|entry| (entry.range.start, Reverse(entry.range.end)));
self.diagnostics = SumTree::from_iter( Self {
entries.into_iter().map(|entry| DiagnosticEntry { diagnostics: SumTree::from_iter(
range: buffer.anchor_before(entry.range.start) entries.into_iter().map(|entry| DiagnosticEntry {
..buffer.anchor_after(entry.range.end), range: buffer.anchor_before(entry.range.start)
diagnostic: entry.diagnostic, ..buffer.anchor_after(entry.range.end),
}), diagnostic: entry.diagnostic,
buffer, }),
); buffer,
),
}
} }
pub fn iter(&self) -> impl Iterator<Item = &DiagnosticEntry<Anchor>> { pub fn iter(&self) -> impl Iterator<Item = &DiagnosticEntry<Anchor>> {