Rip out "diagnostic providers"
This commit is contained in:
parent
496066db59
commit
508b9dc024
16 changed files with 267 additions and 688 deletions
|
@ -66,7 +66,7 @@ pub struct Buffer {
|
|||
parsing_in_background: bool,
|
||||
parse_count: usize,
|
||||
remote_selections: TreeMap<ReplicaId, Arc<[Selection<Anchor>]>>,
|
||||
diagnostic_sets: Vec<DiagnosticSet>,
|
||||
diagnostics: DiagnosticSet,
|
||||
diagnostics_update_count: usize,
|
||||
language_server: Option<LanguageServerState>,
|
||||
deferred_ops: OperationQueue<Operation>,
|
||||
|
@ -77,7 +77,7 @@ pub struct Buffer {
|
|||
pub struct BufferSnapshot {
|
||||
text: text::BufferSnapshot,
|
||||
tree: Option<Tree>,
|
||||
diagnostic_sets: Vec<DiagnosticSet>,
|
||||
diagnostics: DiagnosticSet,
|
||||
remote_selections: TreeMap<ReplicaId, Arc<[Selection<Anchor>]>>,
|
||||
diagnostics_update_count: usize,
|
||||
is_parsing: bool,
|
||||
|
@ -121,7 +121,6 @@ struct LanguageServerSnapshot {
|
|||
pub enum Operation {
|
||||
Buffer(text::Operation),
|
||||
UpdateDiagnostics {
|
||||
provider_name: String,
|
||||
diagnostics: Arc<[DiagnosticEntry<Anchor>]>,
|
||||
lamport_timestamp: clock::Lamport,
|
||||
},
|
||||
|
@ -306,17 +305,11 @@ impl Buffer {
|
|||
);
|
||||
}
|
||||
let snapshot = this.snapshot();
|
||||
for diagnostic_set in message.diagnostic_sets {
|
||||
let (provider_name, entries) = proto::deserialize_diagnostic_set(diagnostic_set);
|
||||
this.apply_diagnostic_update(
|
||||
DiagnosticSet::from_sorted_entries(
|
||||
provider_name,
|
||||
entries.into_iter().cloned(),
|
||||
&snapshot,
|
||||
),
|
||||
cx,
|
||||
);
|
||||
}
|
||||
let entries = proto::deserialize_diagnostics(message.diagnostics);
|
||||
this.apply_diagnostic_update(
|
||||
DiagnosticSet::from_sorted_entries(entries.into_iter().cloned(), &snapshot),
|
||||
cx,
|
||||
);
|
||||
|
||||
Ok(this)
|
||||
}
|
||||
|
@ -338,13 +331,7 @@ impl Buffer {
|
|||
selections: proto::serialize_selections(selections),
|
||||
})
|
||||
.collect(),
|
||||
diagnostic_sets: self
|
||||
.diagnostic_sets
|
||||
.iter()
|
||||
.map(|set| {
|
||||
proto::serialize_diagnostic_set(set.provider_name().to_string(), set.iter())
|
||||
})
|
||||
.collect(),
|
||||
diagnostics: proto::serialize_diagnostics(self.diagnostics.iter()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,7 +366,7 @@ impl Buffer {
|
|||
pending_autoindent: Default::default(),
|
||||
language: None,
|
||||
remote_selections: Default::default(),
|
||||
diagnostic_sets: Default::default(),
|
||||
diagnostics: Default::default(),
|
||||
diagnostics_update_count: 0,
|
||||
language_server: None,
|
||||
deferred_ops: OperationQueue::new(),
|
||||
|
@ -393,7 +380,7 @@ impl Buffer {
|
|||
text: self.text.snapshot(),
|
||||
tree: self.syntax_tree(),
|
||||
remote_selections: self.remote_selections.clone(),
|
||||
diagnostic_sets: self.diagnostic_sets.clone(),
|
||||
diagnostics: self.diagnostics.clone(),
|
||||
diagnostics_update_count: self.diagnostics_update_count,
|
||||
is_parsing: self.parsing_in_background,
|
||||
language: self.language.clone(),
|
||||
|
@ -743,7 +730,6 @@ impl Buffer {
|
|||
|
||||
pub fn update_diagnostics<T>(
|
||||
&mut self,
|
||||
provider_name: Arc<str>,
|
||||
version: Option<i32>,
|
||||
mut diagnostics: Vec<DiagnosticEntry<T>>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
|
@ -833,10 +819,9 @@ impl Buffer {
|
|||
}
|
||||
drop(edits_since_save);
|
||||
|
||||
let set = DiagnosticSet::new(provider_name, sanitized_diagnostics, content);
|
||||
let set = DiagnosticSet::new(sanitized_diagnostics, content);
|
||||
self.apply_diagnostic_update(set.clone(), cx);
|
||||
Ok(Operation::UpdateDiagnostics {
|
||||
provider_name: set.provider_name().to_string(),
|
||||
diagnostics: set.iter().cloned().collect(),
|
||||
lamport_timestamp: self.text.lamport_clock.tick(),
|
||||
})
|
||||
|
@ -1347,17 +1332,12 @@ impl Buffer {
|
|||
unreachable!("buffer operations should never be applied at this layer")
|
||||
}
|
||||
Operation::UpdateDiagnostics {
|
||||
provider_name,
|
||||
diagnostics: diagnostic_set,
|
||||
..
|
||||
} => {
|
||||
let snapshot = self.snapshot();
|
||||
self.apply_diagnostic_update(
|
||||
DiagnosticSet::from_sorted_entries(
|
||||
provider_name,
|
||||
diagnostic_set.iter().cloned(),
|
||||
&snapshot,
|
||||
),
|
||||
DiagnosticSet::from_sorted_entries(diagnostic_set.iter().cloned(), &snapshot),
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
@ -1379,15 +1359,8 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
fn apply_diagnostic_update(&mut self, set: DiagnosticSet, cx: &mut ModelContext<Self>) {
|
||||
match self
|
||||
.diagnostic_sets
|
||||
.binary_search_by_key(&set.provider_name(), |set| set.provider_name())
|
||||
{
|
||||
Ok(ix) => self.diagnostic_sets[ix] = set.clone(),
|
||||
Err(ix) => self.diagnostic_sets.insert(ix, set.clone()),
|
||||
}
|
||||
|
||||
fn apply_diagnostic_update(&mut self, diagnostics: DiagnosticSet, cx: &mut ModelContext<Self>) {
|
||||
self.diagnostics = diagnostics;
|
||||
self.diagnostics_update_count += 1;
|
||||
cx.notify();
|
||||
cx.emit(Event::DiagnosticsUpdated);
|
||||
|
@ -1625,7 +1598,7 @@ impl BufferSnapshot {
|
|||
let mut highlights = None;
|
||||
let mut diagnostic_endpoints = Vec::<DiagnosticEndpoint>::new();
|
||||
if let Some(theme) = theme {
|
||||
for (_, entry) in self.diagnostics_in_range::<_, usize>(range.clone()) {
|
||||
for entry in self.diagnostics_in_range::<_, usize>(range.clone()) {
|
||||
diagnostic_endpoints.push(DiagnosticEndpoint {
|
||||
offset: entry.range.start,
|
||||
is_start: true,
|
||||
|
@ -1756,38 +1729,28 @@ impl BufferSnapshot {
|
|||
pub fn diagnostics_in_range<'a, T, O>(
|
||||
&'a self,
|
||||
search_range: Range<T>,
|
||||
) -> impl 'a + Iterator<Item = (&'a str, DiagnosticEntry<O>)>
|
||||
) -> impl 'a + Iterator<Item = DiagnosticEntry<O>>
|
||||
where
|
||||
T: 'a + Clone + ToOffset,
|
||||
O: 'a + FromAnchor,
|
||||
{
|
||||
self.diagnostic_sets.iter().flat_map(move |set| {
|
||||
set.range(search_range.clone(), self, true)
|
||||
.map(|e| (set.provider_name(), e))
|
||||
})
|
||||
self.diagnostics.range(search_range.clone(), self, true)
|
||||
}
|
||||
|
||||
pub fn diagnostic_groups(&self) -> Vec<DiagnosticGroup<Anchor>> {
|
||||
let mut groups = Vec::new();
|
||||
for set in &self.diagnostic_sets {
|
||||
set.groups(&mut groups, self);
|
||||
}
|
||||
self.diagnostics.groups(&mut groups, self);
|
||||
groups
|
||||
}
|
||||
|
||||
pub fn diagnostic_group<'a, O>(
|
||||
&'a self,
|
||||
provider_name: &str,
|
||||
group_id: usize,
|
||||
) -> impl 'a + Iterator<Item = DiagnosticEntry<O>>
|
||||
where
|
||||
O: 'a + FromAnchor,
|
||||
{
|
||||
self.diagnostic_sets
|
||||
.iter()
|
||||
.find(|s| s.provider_name() == provider_name)
|
||||
.into_iter()
|
||||
.flat_map(move |s| s.group(group_id, self))
|
||||
self.diagnostics.group(group_id, self)
|
||||
}
|
||||
|
||||
pub fn diagnostics_update_count(&self) -> usize {
|
||||
|
@ -1805,7 +1768,7 @@ impl Clone for BufferSnapshot {
|
|||
text: self.text.clone(),
|
||||
tree: self.tree.clone(),
|
||||
remote_selections: self.remote_selections.clone(),
|
||||
diagnostic_sets: self.diagnostic_sets.clone(),
|
||||
diagnostics: self.diagnostics.clone(),
|
||||
diagnostics_update_count: self.diagnostics_update_count,
|
||||
is_parsing: self.is_parsing,
|
||||
language: self.language.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue