diff --git a/crates/ty_server/src/server/api/requests/shutdown.rs b/crates/ty_server/src/server/api/requests/shutdown.rs index 221ff82e09..77c9e78f98 100644 --- a/crates/ty_server/src/server/api/requests/shutdown.rs +++ b/crates/ty_server/src/server/api/requests/shutdown.rs @@ -3,6 +3,7 @@ use crate::server::api::traits::{RequestHandler, SyncRequestHandler}; use crate::session::client::Client; use lsp_types::{WorkspaceDiagnosticReport, WorkspaceDiagnosticReportResult}; +use salsa::Database; pub(crate) struct ShutdownHandler; @@ -28,6 +29,12 @@ impl SyncRequestHandler for ShutdownHandler { session.set_shutdown_requested(true); + // Trigger cancellation for every db to cancel any compute intensive background tasks + // (e.g. workspace diagnostics or workspace symbols). + for db in session.projects_mut() { + db.trigger_cancellation(); + } + Ok(()) } } diff --git a/crates/ty_server/src/session.rs b/crates/ty_server/src/session.rs index 7c13121d1c..4c53371c24 100644 --- a/crates/ty_server/src/session.rs +++ b/crates/ty_server/src/session.rs @@ -427,7 +427,7 @@ impl Session { /// Returns a mutable iterator over all project databases that have been initialized to this point. /// /// This iterator will only yield the default project database if it has been used. - fn projects_mut(&mut self) -> impl Iterator + '_ { + pub(crate) fn projects_mut(&mut self) -> impl Iterator + '_ { self.project_states_mut().map(|project| &mut project.db) }