Skip to content

fix: Fix diagnostics not clearing between flychecks #18864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/rust-analyzer/src/flycheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ struct FlycheckActor {
/// The receiver side of the channel mentioned above.
command_receiver: Option<Receiver<CargoCheckMessage>>,
diagnostics_cleared_for: FxHashSet<Arc<PackageId>>,
diagnostics_cleared_for_all: bool,
diagnostics_received: bool,
}

Expand Down Expand Up @@ -264,6 +265,7 @@ impl FlycheckActor {
command_handle: None,
command_receiver: None,
diagnostics_cleared_for: Default::default(),
diagnostics_cleared_for_all: false,
diagnostics_received: false,
}
}
Expand Down Expand Up @@ -350,6 +352,7 @@ impl FlycheckActor {
package_id: None,
});
}
self.clear_diagnostics_state();

self.report_progress(Progress::DidFinish(res));
}
Expand Down Expand Up @@ -395,6 +398,12 @@ impl FlycheckActor {
package_id: Some(package_id.clone()),
});
}
} else if !self.diagnostics_cleared_for_all {
self.diagnostics_cleared_for_all = true;
self.send(FlycheckMessage::ClearDiagnostics {
id: self.id,
package_id: None,
});
}
self.send(FlycheckMessage::AddDiagnostic {
id: self.id,
Expand All @@ -420,7 +429,12 @@ impl FlycheckActor {
self.command_receiver.take();
self.report_progress(Progress::DidCancel);
}
self.clear_diagnostics_state();
}

fn clear_diagnostics_state(&mut self) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 we should've done this from the start

self.diagnostics_cleared_for.clear();
self.diagnostics_cleared_for_all = false;
self.diagnostics_received = false;
}

Expand Down
Loading