1+ use std:: time:: Duration ;
2+
13use editor:: Editor ;
24use 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} ;
68use language:: Diagnostic ;
79use 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
2023impl 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