Emit an UpdateDiagnostics from Worktree when buffer diagnostics change
This commit is contained in:
@@ -78,7 +78,7 @@ pub struct DiagnosticSummary {
|
||||
}
|
||||
|
||||
impl DiagnosticSummary {
|
||||
fn new<T>(diagnostics: &[DiagnosticEntry<T>]) -> Self {
|
||||
fn new<'a, T: 'a>(diagnostics: impl IntoIterator<Item = &'a DiagnosticEntry<T>>) -> Self {
|
||||
let mut this = Self {
|
||||
error_count: 0,
|
||||
warning_count: 0,
|
||||
|
||||
@@ -1097,15 +1097,43 @@ impl LocalWorktree {
|
||||
buffer
|
||||
});
|
||||
|
||||
this.update(&mut cx, |this, _| {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
let this = this.as_local_mut().unwrap();
|
||||
this.open_buffers.insert(buffer.id(), buffer.downgrade());
|
||||
cx.subscribe(&buffer, |worktree, buffer, event, cx| {
|
||||
worktree
|
||||
.as_local_mut()
|
||||
.unwrap()
|
||||
.on_buffer_event(buffer, event, cx);
|
||||
})
|
||||
.detach();
|
||||
});
|
||||
|
||||
Ok(buffer)
|
||||
})
|
||||
}
|
||||
|
||||
fn on_buffer_event(
|
||||
&mut self,
|
||||
buffer: ModelHandle<Buffer>,
|
||||
event: &language::Event,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
) {
|
||||
match event {
|
||||
language::Event::DiagnosticsUpdated => {
|
||||
let buffer = buffer.read(cx);
|
||||
if let Some(path) = buffer.file().map(|file| file.path().clone()) {
|
||||
let diagnostics = buffer.all_diagnostics();
|
||||
self.diagnostic_summaries
|
||||
.insert(path.clone(), DiagnosticSummary::new(diagnostics));
|
||||
cx.emit(Event::DiagnosticsUpdated(path));
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_remote_buffer(
|
||||
&mut self,
|
||||
envelope: TypedEnvelope<proto::OpenBuffer>,
|
||||
|
||||
Reference in New Issue
Block a user