@@ -19,7 +19,7 @@ use crate::{
19
19
config:: Config ,
20
20
diagnostics:: fetch_native_diagnostics,
21
21
dispatch:: { NotificationDispatcher , RequestDispatcher } ,
22
- global_state:: { file_id_to_url, url_to_file_id, GlobalState } ,
22
+ global_state:: { file_id_to_url, url_to_file_id, FlycheckStatus , GlobalState } ,
23
23
hack_recover_crate_name,
24
24
lsp:: {
25
25
from_proto, to_proto,
@@ -804,10 +804,13 @@ impl GlobalState {
804
804
fn handle_flycheck_msg ( & mut self , message : flycheck:: Message ) {
805
805
match message {
806
806
flycheck:: Message :: AddDiagnostic { id, workspace_root, diagnostic } => {
807
- if !self . diagnostics_received . get ( & id) . copied ( ) . unwrap_or_default ( ) {
807
+ let flycheck_status =
808
+ self . flycheck_status . entry ( id) . or_insert ( FlycheckStatus :: Unknown ) ;
809
+
810
+ if !flycheck_status. should_clear_old_diagnostics ( ) {
808
811
self . diagnostics . clear_check ( id) ;
809
- self . diagnostics_received . insert ( id, true ) ;
810
812
}
813
+ * flycheck_status = FlycheckStatus :: DiagnosticReceived ;
811
814
let snap = self . snapshot ( ) ;
812
815
let diagnostics = crate :: diagnostics:: to_proto:: map_rust_diagnostic_to_lsp (
813
816
& self . config . diagnostics_map ( ) ,
@@ -836,25 +839,32 @@ impl GlobalState {
836
839
flycheck:: Message :: Progress { id, progress } => {
837
840
let ( state, message) = match progress {
838
841
flycheck:: Progress :: DidStart => {
839
- self . diagnostics_received . insert ( id, false ) ;
842
+ self . flycheck_status . insert ( id, FlycheckStatus :: Started ) ;
840
843
( Progress :: Begin , None )
841
844
}
842
845
flycheck:: Progress :: DidCheckCrate ( target) => ( Progress :: Report , Some ( target) ) ,
843
846
flycheck:: Progress :: DidCancel => {
844
847
self . last_flycheck_error = None ;
848
+ // We do not clear
849
+ self . flycheck_status . insert ( id, FlycheckStatus :: Finished ) ;
845
850
( Progress :: End , None )
846
851
}
847
852
flycheck:: Progress :: DidFailToRestart ( err) => {
848
853
self . last_flycheck_error =
849
854
Some ( format ! ( "cargo check failed to start: {err}" ) ) ;
855
+ self . flycheck_status . insert ( id, FlycheckStatus :: Finished ) ;
850
856
return ;
851
857
}
852
858
flycheck:: Progress :: DidFinish ( result) => {
853
859
self . last_flycheck_error =
854
860
result. err ( ) . map ( |err| format ! ( "cargo check failed to start: {err}" ) ) ;
855
- if !self . diagnostics_received . get ( & id) . copied ( ) . unwrap_or_default ( ) {
861
+ let flycheck_status =
862
+ self . flycheck_status . entry ( id) . or_insert ( FlycheckStatus :: Unknown ) ;
863
+
864
+ if !flycheck_status. should_clear_old_diagnostics ( ) {
856
865
self . diagnostics . clear_check ( id) ;
857
866
}
867
+ * flycheck_status = FlycheckStatus :: Finished ;
858
868
( Progress :: End , None )
859
869
}
860
870
} ;
0 commit comments