1
+ use std:: time:: Duration ;
2
+
1
3
use editor:: Editor ;
2
4
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 ,
5
7
} ;
6
8
use language:: Diagnostic ;
7
9
use ui:: { h_flex, prelude:: * , Button , ButtonLike , Color , Icon , IconName , Label , Tooltip } ;
@@ -15,6 +17,7 @@ pub struct DiagnosticIndicator {
15
17
workspace : WeakView < Workspace > ,
16
18
current_diagnostic : Option < Diagnostic > ,
17
19
_observe_active_editor : Option < Subscription > ,
20
+ diagnostics_update : Task < ( ) > ,
18
21
}
19
22
20
23
impl Render for DiagnosticIndicator {
@@ -126,6 +129,7 @@ impl DiagnosticIndicator {
126
129
workspace : workspace. weak_handle ( ) ,
127
130
current_diagnostic : None ,
128
131
_observe_active_editor : None ,
132
+ diagnostics_update : Task :: ready ( ( ) ) ,
129
133
}
130
134
}
131
135
@@ -149,8 +153,17 @@ impl DiagnosticIndicator {
149
153
. min_by_key ( |entry| ( entry. diagnostic . severity , entry. range . len ( ) ) )
150
154
. map ( |entry| entry. diagnostic ) ;
151
155
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
+ } ) ;
154
167
}
155
168
}
156
169
}
0 commit comments