@@ -673,27 +673,31 @@ impl FlycheckActor {
673673 if self . diagnostics_received == DiagnosticsReceived :: NotYet {
674674 tracing:: trace!( flycheck_id = self . id, "clearing diagnostics" ) ;
675675 // We finished without receiving any diagnostics.
676- // Clear everything for good measure
677- match & self . scope {
678- FlycheckScope :: Workspace => {
679- self . send ( FlycheckMessage :: ClearDiagnostics {
680- id : self . id ,
681- kind : ClearDiagnosticsKind :: All ( ClearScope :: Workspace ) ,
682- } ) ;
683- }
684- FlycheckScope :: Package { package, workspace_deps } => {
685- for pkg in
686- std:: iter:: once ( package) . chain ( workspace_deps. iter ( ) . flatten ( ) )
687- {
688- self . send ( FlycheckMessage :: ClearDiagnostics {
689- id : self . id ,
690- kind : ClearDiagnosticsKind :: All ( ClearScope :: Package (
691- pkg. clone ( ) ,
692- ) ) ,
693- } ) ;
694- }
695- }
696- }
676+ //
677+ // `cargo check` generally outputs something, even if there are no
678+ // warnings/errors, so we always know which package was checked.
679+ //
680+ // ```text
681+ // $ cargo check --message-format=json 2>/dev/null
682+ // {"reason":"compiler-artifact","package_id":"path+file:///Users/wilfred/tmp/scratch#0.1.0",...}
683+ // ```
684+ //
685+ // However, rustc only returns JSON if there are diagnostics present, so a
686+ // build without warnings or errors has an empty output.
687+ //
688+ // ```
689+ // $ rustc --error-format=json bad.rs
690+ // {"$message_type":"diagnostic","message":"mismatched types","...}
691+ //
692+ // $ rustc --error-format=json good.rs
693+ // ```
694+ //
695+ // So if we got zero diagnostics, it was almost certainly a check that
696+ // wasn't specific to a package.
697+ self . send ( FlycheckMessage :: ClearDiagnostics {
698+ id : self . id ,
699+ kind : ClearDiagnosticsKind :: All ( ClearScope :: Workspace ) ,
700+ } ) ;
697701 } else if res. is_ok ( ) {
698702 // We clear diagnostics for packages on
699703 // `[CargoCheckMessage::CompilerArtifact]` but there seem to be setups where
0 commit comments