Move state trackig of diagnostic clearing inside FlycheckActor
This commit is contained in:
parent
4be8e5a372
commit
f476d37e4e
@ -163,6 +163,9 @@ pub enum Message {
|
|||||||
/// Request adding a diagnostic with fixes included to a file
|
/// Request adding a diagnostic with fixes included to a file
|
||||||
AddDiagnostic { id: usize, workspace_root: AbsPathBuf, diagnostic: Diagnostic },
|
AddDiagnostic { id: usize, workspace_root: AbsPathBuf, diagnostic: Diagnostic },
|
||||||
|
|
||||||
|
/// Request clearing all previous diagnostics
|
||||||
|
ClearDiagnostics { id: usize },
|
||||||
|
|
||||||
/// Request check progress notification to client
|
/// Request check progress notification to client
|
||||||
Progress {
|
Progress {
|
||||||
/// Flycheck instance ID
|
/// Flycheck instance ID
|
||||||
@ -180,6 +183,9 @@ impl fmt::Debug for Message {
|
|||||||
.field("workspace_root", workspace_root)
|
.field("workspace_root", workspace_root)
|
||||||
.field("diagnostic_code", &diagnostic.code.as_ref().map(|it| &it.code))
|
.field("diagnostic_code", &diagnostic.code.as_ref().map(|it| &it.code))
|
||||||
.finish(),
|
.finish(),
|
||||||
|
Message::ClearDiagnostics { id } => {
|
||||||
|
f.debug_struct("ClearDiagnostics").field("id", id).finish()
|
||||||
|
}
|
||||||
Message::Progress { id, progress } => {
|
Message::Progress { id, progress } => {
|
||||||
f.debug_struct("Progress").field("id", id).field("progress", progress).finish()
|
f.debug_struct("Progress").field("id", id).field("progress", progress).finish()
|
||||||
}
|
}
|
||||||
@ -220,6 +226,8 @@ struct FlycheckActor {
|
|||||||
command_handle: Option<CommandHandle<CargoCheckMessage>>,
|
command_handle: Option<CommandHandle<CargoCheckMessage>>,
|
||||||
/// The receiver side of the channel mentioned above.
|
/// The receiver side of the channel mentioned above.
|
||||||
command_receiver: Option<Receiver<CargoCheckMessage>>,
|
command_receiver: Option<Receiver<CargoCheckMessage>>,
|
||||||
|
|
||||||
|
status: FlycheckStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Event {
|
enum Event {
|
||||||
@ -227,6 +235,13 @@ enum Event {
|
|||||||
CheckEvent(Option<CargoCheckMessage>),
|
CheckEvent(Option<CargoCheckMessage>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
enum FlycheckStatus {
|
||||||
|
Started,
|
||||||
|
DiagnosticSent,
|
||||||
|
Finished,
|
||||||
|
}
|
||||||
|
|
||||||
const SAVED_FILE_PLACEHOLDER: &str = "$saved_file";
|
const SAVED_FILE_PLACEHOLDER: &str = "$saved_file";
|
||||||
|
|
||||||
impl FlycheckActor {
|
impl FlycheckActor {
|
||||||
@ -248,6 +263,7 @@ impl FlycheckActor {
|
|||||||
manifest_path,
|
manifest_path,
|
||||||
command_handle: None,
|
command_handle: None,
|
||||||
command_receiver: None,
|
command_receiver: None,
|
||||||
|
status: FlycheckStatus::Finished,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,12 +314,14 @@ impl FlycheckActor {
|
|||||||
self.command_handle = Some(command_handle);
|
self.command_handle = Some(command_handle);
|
||||||
self.command_receiver = Some(receiver);
|
self.command_receiver = Some(receiver);
|
||||||
self.report_progress(Progress::DidStart);
|
self.report_progress(Progress::DidStart);
|
||||||
|
self.status = FlycheckStatus::Started;
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
self.report_progress(Progress::DidFailToRestart(format!(
|
self.report_progress(Progress::DidFailToRestart(format!(
|
||||||
"Failed to run the following command: {} error={}",
|
"Failed to run the following command: {} error={}",
|
||||||
formatted_command, error
|
formatted_command, error
|
||||||
)));
|
)));
|
||||||
|
self.status = FlycheckStatus::Finished;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -323,7 +341,11 @@ impl FlycheckActor {
|
|||||||
error
|
error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if self.status == FlycheckStatus::Started {
|
||||||
|
self.send(Message::ClearDiagnostics { id: self.id });
|
||||||
|
}
|
||||||
self.report_progress(Progress::DidFinish(res));
|
self.report_progress(Progress::DidFinish(res));
|
||||||
|
self.status = FlycheckStatus::Finished;
|
||||||
}
|
}
|
||||||
Event::CheckEvent(Some(message)) => match message {
|
Event::CheckEvent(Some(message)) => match message {
|
||||||
CargoCheckMessage::CompilerArtifact(msg) => {
|
CargoCheckMessage::CompilerArtifact(msg) => {
|
||||||
@ -341,11 +363,15 @@ impl FlycheckActor {
|
|||||||
message = msg.message,
|
message = msg.message,
|
||||||
"diagnostic received"
|
"diagnostic received"
|
||||||
);
|
);
|
||||||
|
if self.status == FlycheckStatus::Started {
|
||||||
|
self.send(Message::ClearDiagnostics { id: self.id });
|
||||||
|
}
|
||||||
self.send(Message::AddDiagnostic {
|
self.send(Message::AddDiagnostic {
|
||||||
id: self.id,
|
id: self.id,
|
||||||
workspace_root: self.root.clone(),
|
workspace_root: self.root.clone(),
|
||||||
diagnostic: msg,
|
diagnostic: msg,
|
||||||
});
|
});
|
||||||
|
self.status = FlycheckStatus::DiagnosticSent;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -362,6 +388,7 @@ impl FlycheckActor {
|
|||||||
);
|
);
|
||||||
command_handle.cancel();
|
command_handle.cancel();
|
||||||
self.report_progress(Progress::DidCancel);
|
self.report_progress(Progress::DidCancel);
|
||||||
|
self.status = FlycheckStatus::Finished;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,6 @@ pub(crate) struct GlobalState {
|
|||||||
pub(crate) flycheck_sender: Sender<flycheck::Message>,
|
pub(crate) flycheck_sender: Sender<flycheck::Message>,
|
||||||
pub(crate) flycheck_receiver: Receiver<flycheck::Message>,
|
pub(crate) flycheck_receiver: Receiver<flycheck::Message>,
|
||||||
pub(crate) last_flycheck_error: Option<String>,
|
pub(crate) last_flycheck_error: Option<String>,
|
||||||
pub(crate) flycheck_status: FxHashMap<usize, FlycheckStatus>,
|
|
||||||
|
|
||||||
// Test explorer
|
// Test explorer
|
||||||
pub(crate) test_run_session: Option<Vec<flycheck::CargoTestHandle>>,
|
pub(crate) test_run_session: Option<Vec<flycheck::CargoTestHandle>>,
|
||||||
@ -166,14 +165,6 @@ pub(crate) struct GlobalStateSnapshot {
|
|||||||
pub(crate) flycheck: Arc<[FlycheckHandle]>,
|
pub(crate) flycheck: Arc<[FlycheckHandle]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub(crate) enum FlycheckStatus {
|
|
||||||
Unknown,
|
|
||||||
Started,
|
|
||||||
DiagnosticReceived,
|
|
||||||
Finished,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::panic::UnwindSafe for GlobalStateSnapshot {}
|
impl std::panic::UnwindSafe for GlobalStateSnapshot {}
|
||||||
|
|
||||||
impl GlobalState {
|
impl GlobalState {
|
||||||
@ -233,7 +224,6 @@ impl GlobalState {
|
|||||||
flycheck_sender,
|
flycheck_sender,
|
||||||
flycheck_receiver,
|
flycheck_receiver,
|
||||||
last_flycheck_error: None,
|
last_flycheck_error: None,
|
||||||
flycheck_status: FxHashMap::default(),
|
|
||||||
|
|
||||||
test_run_session: None,
|
test_run_session: None,
|
||||||
test_run_sender,
|
test_run_sender,
|
||||||
@ -521,12 +511,3 @@ pub(crate) fn url_to_file_id(vfs: &vfs::Vfs, url: &Url) -> anyhow::Result<FileId
|
|||||||
let res = vfs.file_id(&path).ok_or_else(|| anyhow::format_err!("file not found: {path}"))?;
|
let res = vfs.file_id(&path).ok_or_else(|| anyhow::format_err!("file not found: {path}"))?;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FlycheckStatus {
|
|
||||||
pub(crate) fn should_clear_old_diagnostics(&self) -> bool {
|
|
||||||
match self {
|
|
||||||
FlycheckStatus::Unknown | FlycheckStatus::Started => false,
|
|
||||||
FlycheckStatus::DiagnosticReceived | FlycheckStatus::Finished => true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -19,7 +19,7 @@ use crate::{
|
|||||||
config::Config,
|
config::Config,
|
||||||
diagnostics::fetch_native_diagnostics,
|
diagnostics::fetch_native_diagnostics,
|
||||||
dispatch::{NotificationDispatcher, RequestDispatcher},
|
dispatch::{NotificationDispatcher, RequestDispatcher},
|
||||||
global_state::{file_id_to_url, url_to_file_id, FlycheckStatus, GlobalState},
|
global_state::{file_id_to_url, url_to_file_id, GlobalState},
|
||||||
hack_recover_crate_name,
|
hack_recover_crate_name,
|
||||||
lsp::{
|
lsp::{
|
||||||
from_proto, to_proto,
|
from_proto, to_proto,
|
||||||
@ -804,13 +804,6 @@ impl GlobalState {
|
|||||||
fn handle_flycheck_msg(&mut self, message: flycheck::Message) {
|
fn handle_flycheck_msg(&mut self, message: flycheck::Message) {
|
||||||
match message {
|
match message {
|
||||||
flycheck::Message::AddDiagnostic { id, workspace_root, diagnostic } => {
|
flycheck::Message::AddDiagnostic { id, workspace_root, diagnostic } => {
|
||||||
let flycheck_status =
|
|
||||||
self.flycheck_status.entry(id).or_insert(FlycheckStatus::Unknown);
|
|
||||||
|
|
||||||
if !flycheck_status.should_clear_old_diagnostics() {
|
|
||||||
self.diagnostics.clear_check(id);
|
|
||||||
}
|
|
||||||
*flycheck_status = FlycheckStatus::DiagnosticReceived;
|
|
||||||
let snap = self.snapshot();
|
let snap = self.snapshot();
|
||||||
let diagnostics = crate::diagnostics::to_proto::map_rust_diagnostic_to_lsp(
|
let diagnostics = crate::diagnostics::to_proto::map_rust_diagnostic_to_lsp(
|
||||||
&self.config.diagnostics_map(),
|
&self.config.diagnostics_map(),
|
||||||
@ -836,35 +829,24 @@ impl GlobalState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flycheck::Message::ClearDiagnostics { id } => self.diagnostics.clear_check(id),
|
||||||
|
|
||||||
flycheck::Message::Progress { id, progress } => {
|
flycheck::Message::Progress { id, progress } => {
|
||||||
let (state, message) = match progress {
|
let (state, message) = match progress {
|
||||||
flycheck::Progress::DidStart => {
|
flycheck::Progress::DidStart => (Progress::Begin, None),
|
||||||
self.flycheck_status.insert(id, FlycheckStatus::Started);
|
|
||||||
(Progress::Begin, None)
|
|
||||||
}
|
|
||||||
flycheck::Progress::DidCheckCrate(target) => (Progress::Report, Some(target)),
|
flycheck::Progress::DidCheckCrate(target) => (Progress::Report, Some(target)),
|
||||||
flycheck::Progress::DidCancel => {
|
flycheck::Progress::DidCancel => {
|
||||||
self.last_flycheck_error = None;
|
self.last_flycheck_error = None;
|
||||||
// We do not clear
|
|
||||||
self.flycheck_status.insert(id, FlycheckStatus::Finished);
|
|
||||||
(Progress::End, None)
|
(Progress::End, None)
|
||||||
}
|
}
|
||||||
flycheck::Progress::DidFailToRestart(err) => {
|
flycheck::Progress::DidFailToRestart(err) => {
|
||||||
self.last_flycheck_error =
|
self.last_flycheck_error =
|
||||||
Some(format!("cargo check failed to start: {err}"));
|
Some(format!("cargo check failed to start: {err}"));
|
||||||
self.flycheck_status.insert(id, FlycheckStatus::Finished);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
flycheck::Progress::DidFinish(result) => {
|
flycheck::Progress::DidFinish(result) => {
|
||||||
self.last_flycheck_error =
|
self.last_flycheck_error =
|
||||||
result.err().map(|err| format!("cargo check failed to start: {err}"));
|
result.err().map(|err| format!("cargo check failed to start: {err}"));
|
||||||
let flycheck_status =
|
|
||||||
self.flycheck_status.entry(id).or_insert(FlycheckStatus::Unknown);
|
|
||||||
|
|
||||||
if !flycheck_status.should_clear_old_diagnostics() {
|
|
||||||
self.diagnostics.clear_check(id);
|
|
||||||
}
|
|
||||||
*flycheck_status = FlycheckStatus::Finished;
|
|
||||||
(Progress::End, None)
|
(Progress::End, None)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user