Skip to content

Commit c5e05df

Browse files
authored
[ty] Cancel background tasks when shutdown is requested (#20039)
1 parent 7a44ea6 commit c5e05df

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

crates/ty_server/src/server/api/requests/shutdown.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::server::api::traits::{RequestHandler, SyncRequestHandler};
33
use crate::session::client::Client;
44

55
use lsp_types::{WorkspaceDiagnosticReport, WorkspaceDiagnosticReportResult};
6+
use salsa::Database;
67

78
pub(crate) struct ShutdownHandler;
89

@@ -28,6 +29,12 @@ impl SyncRequestHandler for ShutdownHandler {
2829

2930
session.set_shutdown_requested(true);
3031

32+
// Trigger cancellation for every db to cancel any compute intensive background tasks
33+
// (e.g. workspace diagnostics or workspace symbols).
34+
for db in session.projects_mut() {
35+
db.trigger_cancellation();
36+
}
37+
3138
Ok(())
3239
}
3340
}

crates/ty_server/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl Session {
427427
/// Returns a mutable iterator over all project databases that have been initialized to this point.
428428
///
429429
/// This iterator will only yield the default project database if it has been used.
430-
fn projects_mut(&mut self) -> impl Iterator<Item = &'_ mut ProjectDatabase> + '_ {
430+
pub(crate) fn projects_mut(&mut self) -> impl Iterator<Item = &'_ mut ProjectDatabase> + '_ {
431431
self.project_states_mut().map(|project| &mut project.db)
432432
}
433433

0 commit comments

Comments
 (0)