Skip to content

Commit

Permalink
Auto merge of #18065 - Veykril:catchy-diagnostics, r=Veykril
Browse files Browse the repository at this point in the history
fix: Catch panics from diagnostics computation
  • Loading branch information
bors committed Sep 6, 2024
2 parents ecd835d + 7e5a0e5 commit 56fde6e
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use std::{
fmt,
ops::Div as _,
panic::AssertUnwindSafe,
time::{Duration, Instant},
};

Expand Down Expand Up @@ -552,23 +553,33 @@ impl GlobalState {
let fetch_semantic =
self.vfs_done && self.fetch_workspaces_queue.last_op_result().is_some();
move |sender| {
let diags = fetch_native_diagnostics(
&snapshot,
subscriptions.clone(),
slice.clone(),
NativeDiagnosticsFetchKind::Syntax,
);
// We aren't observing the semantics token cache here
let snapshot = AssertUnwindSafe(&snapshot);
let Ok(diags) = std::panic::catch_unwind(|| {
fetch_native_diagnostics(
&snapshot,
subscriptions.clone(),
slice.clone(),
NativeDiagnosticsFetchKind::Syntax,
)
}) else {
return;
};
sender
.send(Task::Diagnostics(DiagnosticsTaskKind::Syntax(generation, diags)))
.unwrap();

if fetch_semantic {
let diags = fetch_native_diagnostics(
&snapshot,
subscriptions,
slice,
NativeDiagnosticsFetchKind::Semantic,
);
let Ok(diags) = std::panic::catch_unwind(|| {
fetch_native_diagnostics(
&snapshot,
subscriptions.clone(),
slice.clone(),
NativeDiagnosticsFetchKind::Semantic,
)
}) else {
return;
};
sender
.send(Task::Diagnostics(DiagnosticsTaskKind::Semantic(
generation, diags,
Expand Down

0 comments on commit 56fde6e

Please sign in to comment.