[ty] Cancel background tasks when shutdown is requested (#20039)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run

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 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(())
}
}

View file

@ -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<Item = &'_ mut ProjectDatabase> + '_ {
pub(crate) fn projects_mut(&mut self) -> impl Iterator<Item = &'_ mut ProjectDatabase> + '_ {
self.project_states_mut().map(|project| &mut project.db)
}