[ty] Cancel background tasks when shutdown is requested (#20039)

This commit is contained in:
Micha Reiser 2025-08-22 10:20:13 +02:00 committed by GitHub
parent 7a44ea680e
commit c5e05df966
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -3,6 +3,7 @@ use crate::server::api::traits::{RequestHandler, SyncRequestHandler};
use crate::session::client::Client; use crate::session::client::Client;
use lsp_types::{WorkspaceDiagnosticReport, WorkspaceDiagnosticReportResult}; use lsp_types::{WorkspaceDiagnosticReport, WorkspaceDiagnosticReportResult};
use salsa::Database;
pub(crate) struct ShutdownHandler; pub(crate) struct ShutdownHandler;
@ -28,6 +29,12 @@ impl SyncRequestHandler for ShutdownHandler {
session.set_shutdown_requested(true); 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(()) Ok(())
} }
} }

View File

@ -427,7 +427,7 @@ impl Session {
/// Returns a mutable iterator over all project databases that have been initialized to this point. /// 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. /// This iterator will only yield the default project database if it has been used.
fn projects_mut(&mut self) -> impl Iterator<Item = &'_ mut ProjectDatabase> + '_ { pub(crate) fn projects_mut(&mut self) -> impl Iterator<Item = &'_ mut ProjectDatabase> + '_ {
self.project_states_mut().map(|project| &mut project.db) self.project_states_mut().map(|project| &mut project.db)
} }