@@ -163,6 +163,9 @@ pub enum Message {
163163 /// Request adding a diagnostic with fixes included to a file
164164 AddDiagnostic { id : usize , workspace_root : AbsPathBuf , diagnostic : Diagnostic } ,
165165
166+ /// Request clearing all previous diagnostics
167+ ClearDiagnostics { id : usize } ,
168+
166169 /// Request check progress notification to client
167170 Progress {
168171 /// Flycheck instance ID
@@ -180,6 +183,9 @@ impl fmt::Debug for Message {
180183 . field ( "workspace_root" , workspace_root)
181184 . field ( "diagnostic_code" , & diagnostic. code . as_ref ( ) . map ( |it| & it. code ) )
182185 . finish ( ) ,
186+ Message :: ClearDiagnostics { id } => {
187+ f. debug_struct ( "ClearDiagnostics" ) . field ( "id" , id) . finish ( )
188+ }
183189 Message :: Progress { id, progress } => {
184190 f. debug_struct ( "Progress" ) . field ( "id" , id) . field ( "progress" , progress) . finish ( )
185191 }
@@ -220,13 +226,22 @@ struct FlycheckActor {
220226 command_handle : Option < CommandHandle < CargoCheckMessage > > ,
221227 /// The receiver side of the channel mentioned above.
222228 command_receiver : Option < Receiver < CargoCheckMessage > > ,
229+
230+ status : FlycheckStatus ,
223231}
224232
225233enum Event {
226234 RequestStateChange ( StateChange ) ,
227235 CheckEvent ( Option < CargoCheckMessage > ) ,
228236}
229237
238+ #[ derive( PartialEq ) ]
239+ enum FlycheckStatus {
240+ Started ,
241+ DiagnosticSent ,
242+ Finished ,
243+ }
244+
230245const SAVED_FILE_PLACEHOLDER : & str = "$saved_file" ;
231246
232247impl FlycheckActor {
@@ -248,6 +263,7 @@ impl FlycheckActor {
248263 manifest_path,
249264 command_handle : None ,
250265 command_receiver : None ,
266+ status : FlycheckStatus :: Finished ,
251267 }
252268 }
253269
@@ -298,12 +314,14 @@ impl FlycheckActor {
298314 self . command_handle = Some ( command_handle) ;
299315 self . command_receiver = Some ( receiver) ;
300316 self . report_progress ( Progress :: DidStart ) ;
317+ self . status = FlycheckStatus :: Started ;
301318 }
302319 Err ( error) => {
303320 self . report_progress ( Progress :: DidFailToRestart ( format ! (
304321 "Failed to run the following command: {} error={}" ,
305322 formatted_command, error
306323 ) ) ) ;
324+ self . status = FlycheckStatus :: Finished ;
307325 }
308326 }
309327 }
@@ -323,7 +341,11 @@ impl FlycheckActor {
323341 error
324342 ) ;
325343 }
344+ if self . status == FlycheckStatus :: Started {
345+ self . send ( Message :: ClearDiagnostics { id : self . id } ) ;
346+ }
326347 self . report_progress ( Progress :: DidFinish ( res) ) ;
348+ self . status = FlycheckStatus :: Finished ;
327349 }
328350 Event :: CheckEvent ( Some ( message) ) => match message {
329351 CargoCheckMessage :: CompilerArtifact ( msg) => {
@@ -341,11 +363,15 @@ impl FlycheckActor {
341363 message = msg. message,
342364 "diagnostic received"
343365 ) ;
366+ if self . status == FlycheckStatus :: Started {
367+ self . send ( Message :: ClearDiagnostics { id : self . id } ) ;
368+ }
344369 self . send ( Message :: AddDiagnostic {
345370 id : self . id ,
346371 workspace_root : self . root . clone ( ) ,
347372 diagnostic : msg,
348373 } ) ;
374+ self . status = FlycheckStatus :: DiagnosticSent ;
349375 }
350376 } ,
351377 }
@@ -362,6 +388,7 @@ impl FlycheckActor {
362388 ) ;
363389 command_handle. cancel ( ) ;
364390 self . report_progress ( Progress :: DidCancel ) ;
391+ self . status = FlycheckStatus :: Finished ;
365392 }
366393 }
367394
0 commit comments