@@ -19,7 +19,7 @@ use crate::{
1919 config:: Config ,
2020 diagnostics:: fetch_native_diagnostics,
2121 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 } ,
2323 hack_recover_crate_name,
2424 lsp:: {
2525 from_proto, to_proto,
@@ -804,10 +804,13 @@ impl GlobalState {
804804 fn handle_flycheck_msg ( & mut self , message : flycheck:: Message ) {
805805 match message {
806806 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 ( ) {
808811 self . diagnostics . clear_check ( id) ;
809- self . diagnostics_received . insert ( id, true ) ;
810812 }
813+ * flycheck_status = FlycheckStatus :: DiagnosticReceived ;
811814 let snap = self . snapshot ( ) ;
812815 let diagnostics = crate :: diagnostics:: to_proto:: map_rust_diagnostic_to_lsp (
813816 & self . config . diagnostics_map ( ) ,
@@ -836,25 +839,32 @@ impl GlobalState {
836839 flycheck:: Message :: Progress { id, progress } => {
837840 let ( state, message) = match progress {
838841 flycheck:: Progress :: DidStart => {
839- self . diagnostics_received . insert ( id, false ) ;
842+ self . flycheck_status . insert ( id, FlycheckStatus :: Started ) ;
840843 ( Progress :: Begin , None )
841844 }
842845 flycheck:: Progress :: DidCheckCrate ( target) => ( Progress :: Report , Some ( target) ) ,
843846 flycheck:: Progress :: DidCancel => {
844847 self . last_flycheck_error = None ;
848+ // We do not clear
849+ self . flycheck_status . insert ( id, FlycheckStatus :: Finished ) ;
845850 ( Progress :: End , None )
846851 }
847852 flycheck:: Progress :: DidFailToRestart ( err) => {
848853 self . last_flycheck_error =
849854 Some ( format ! ( "cargo check failed to start: {err}" ) ) ;
855+ self . flycheck_status . insert ( id, FlycheckStatus :: Finished ) ;
850856 return ;
851857 }
852858 flycheck:: Progress :: DidFinish ( result) => {
853859 self . last_flycheck_error =
854860 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 ( ) {
856865 self . diagnostics . clear_check ( id) ;
857866 }
867+ * flycheck_status = FlycheckStatus :: Finished ;
858868 ( Progress :: End , None )
859869 }
860870 } ;
0 commit comments