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,
future::Future,
iter::{Iterator, Peekable},
mem,
ops::{Deref, DerefMut, Range},
path::{Path, PathBuf},
str,
@ -794,8 +793,7 @@ impl Buffer {
}
drop(edits_since_save);
let mut diagnostics = mem::take(&mut self.diagnostics);
diagnostics.reset(
let new_diagnostics = DiagnosticSet::new(
diagnostics_by_group_id
.into_values()
.flat_map(|mut diagnostics| {
@ -806,9 +804,9 @@ impl Buffer {
primary.diagnostic.is_primary = true;
diagnostics
}),
self,
content,
);
self.diagnostics = diagnostics;
self.diagnostics = new_diagnostics;
if let Some(version) = version {
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
I: IntoIterator<Item = DiagnosticEntry<PointUtf16>>,
{
let mut entries = iter.into_iter().collect::<Vec<_>>();
entries.sort_unstable_by_key(|entry| (entry.range.start, Reverse(entry.range.end)));
self.diagnostics = SumTree::from_iter(
entries.into_iter().map(|entry| DiagnosticEntry {
range: buffer.anchor_before(entry.range.start)
..buffer.anchor_after(entry.range.end),
diagnostic: entry.diagnostic,
}),
buffer,
);
Self {
diagnostics: SumTree::from_iter(
entries.into_iter().map(|entry| DiagnosticEntry {
range: buffer.anchor_before(entry.range.start)
..buffer.anchor_after(entry.range.end),
diagnostic: entry.diagnostic,
}),
buffer,
),
}
}
pub fn iter(&self) -> impl Iterator<Item = &DiagnosticEntry<Anchor>> {