Skip to content

Commit a0f2c07

Browse files
Debounce diagnostics status bar updates (#21463)
Closes #20797 Release Notes: - Fixed diagnostics status bar flashing when typing
1 parent 1270ef3 commit a0f2c07

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

crates/diagnostics/src/items.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
use std::time::Duration;
2+
13
use editor::Editor;
24
use gpui::{
3-
EventEmitter, IntoElement, ParentElement, Render, Styled, Subscription, View, ViewContext,
4-
WeakView,
5+
EventEmitter, IntoElement, ParentElement, Render, Styled, Subscription, Task, View,
6+
ViewContext, WeakView,
57
};
68
use language::Diagnostic;
79
use ui::{h_flex, prelude::*, Button, ButtonLike, Color, Icon, IconName, Label, Tooltip};
@@ -15,6 +17,7 @@ pub struct DiagnosticIndicator {
1517
workspace: WeakView<Workspace>,
1618
current_diagnostic: Option<Diagnostic>,
1719
_observe_active_editor: Option<Subscription>,
20+
diagnostics_update: Task<()>,
1821
}
1922

2023
impl Render for DiagnosticIndicator {
@@ -126,6 +129,7 @@ impl DiagnosticIndicator {
126129
workspace: workspace.weak_handle(),
127130
current_diagnostic: None,
128131
_observe_active_editor: None,
132+
diagnostics_update: Task::ready(()),
129133
}
130134
}
131135

@@ -149,8 +153,17 @@ impl DiagnosticIndicator {
149153
.min_by_key(|entry| (entry.diagnostic.severity, entry.range.len()))
150154
.map(|entry| entry.diagnostic);
151155
if new_diagnostic != self.current_diagnostic {
152-
self.current_diagnostic = new_diagnostic;
153-
cx.notify();
156+
self.diagnostics_update = cx.spawn(|diagnostics_indicator, mut cx| async move {
157+
cx.background_executor()
158+
.timer(Duration::from_millis(50))
159+
.await;
160+
diagnostics_indicator
161+
.update(&mut cx, |diagnostics_indicator, cx| {
162+
diagnostics_indicator.current_diagnostic = new_diagnostic;
163+
cx.notify();
164+
})
165+
.ok();
166+
});
154167
}
155168
}
156169
}

0 commit comments

Comments
 (0)