@@ -163,6 +163,9 @@ pub enum Message {
163
163
/// Request adding a diagnostic with fixes included to a file
164
164
AddDiagnostic { id : usize , workspace_root : AbsPathBuf , diagnostic : Diagnostic } ,
165
165
166
+ /// Request clearing all previous diagnostics
167
+ ClearDiagnostics { id : usize } ,
168
+
166
169
/// Request check progress notification to client
167
170
Progress {
168
171
/// Flycheck instance ID
@@ -180,6 +183,9 @@ impl fmt::Debug for Message {
180
183
. field ( "workspace_root" , workspace_root)
181
184
. field ( "diagnostic_code" , & diagnostic. code . as_ref ( ) . map ( |it| & it. code ) )
182
185
. finish ( ) ,
186
+ Message :: ClearDiagnostics { id } => {
187
+ f. debug_struct ( "ClearDiagnostics" ) . field ( "id" , id) . finish ( )
188
+ }
183
189
Message :: Progress { id, progress } => {
184
190
f. debug_struct ( "Progress" ) . field ( "id" , id) . field ( "progress" , progress) . finish ( )
185
191
}
@@ -220,13 +226,22 @@ struct FlycheckActor {
220
226
command_handle : Option < CommandHandle < CargoCheckMessage > > ,
221
227
/// The receiver side of the channel mentioned above.
222
228
command_receiver : Option < Receiver < CargoCheckMessage > > ,
229
+
230
+ status : FlycheckStatus ,
223
231
}
224
232
225
233
enum Event {
226
234
RequestStateChange ( StateChange ) ,
227
235
CheckEvent ( Option < CargoCheckMessage > ) ,
228
236
}
229
237
238
+ #[ derive( PartialEq ) ]
239
+ enum FlycheckStatus {
240
+ Started ,
241
+ DiagnosticSent ,
242
+ Finished ,
243
+ }
244
+
230
245
const SAVED_FILE_PLACEHOLDER : & str = "$saved_file" ;
231
246
232
247
impl FlycheckActor {
@@ -248,6 +263,7 @@ impl FlycheckActor {
248
263
manifest_path,
249
264
command_handle : None ,
250
265
command_receiver : None ,
266
+ status : FlycheckStatus :: Finished ,
251
267
}
252
268
}
253
269
@@ -298,12 +314,14 @@ impl FlycheckActor {
298
314
self . command_handle = Some ( command_handle) ;
299
315
self . command_receiver = Some ( receiver) ;
300
316
self . report_progress ( Progress :: DidStart ) ;
317
+ self . status = FlycheckStatus :: Started ;
301
318
}
302
319
Err ( error) => {
303
320
self . report_progress ( Progress :: DidFailToRestart ( format ! (
304
321
"Failed to run the following command: {} error={}" ,
305
322
formatted_command, error
306
323
) ) ) ;
324
+ self . status = FlycheckStatus :: Finished ;
307
325
}
308
326
}
309
327
}
@@ -323,7 +341,11 @@ impl FlycheckActor {
323
341
error
324
342
) ;
325
343
}
344
+ if self . status == FlycheckStatus :: Started {
345
+ self . send ( Message :: ClearDiagnostics { id : self . id } ) ;
346
+ }
326
347
self . report_progress ( Progress :: DidFinish ( res) ) ;
348
+ self . status = FlycheckStatus :: Finished ;
327
349
}
328
350
Event :: CheckEvent ( Some ( message) ) => match message {
329
351
CargoCheckMessage :: CompilerArtifact ( msg) => {
@@ -341,11 +363,15 @@ impl FlycheckActor {
341
363
message = msg. message,
342
364
"diagnostic received"
343
365
) ;
366
+ if self . status == FlycheckStatus :: Started {
367
+ self . send ( Message :: ClearDiagnostics { id : self . id } ) ;
368
+ }
344
369
self . send ( Message :: AddDiagnostic {
345
370
id : self . id ,
346
371
workspace_root : self . root . clone ( ) ,
347
372
diagnostic : msg,
348
373
} ) ;
374
+ self . status = FlycheckStatus :: DiagnosticSent ;
349
375
}
350
376
} ,
351
377
}
@@ -362,6 +388,7 @@ impl FlycheckActor {
362
388
) ;
363
389
command_handle. cancel ( ) ;
364
390
self . report_progress ( Progress :: DidCancel ) ;
391
+ self . status = FlycheckStatus :: Finished ;
365
392
}
366
393
}
367
394
0 commit comments