mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:21 +00:00
Support cancellation requests (#18627)
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 / 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 / mkdocs (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 (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
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 / 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 / mkdocs (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 (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
This commit is contained in:
parent
1f27d53fd5
commit
015222900f
46 changed files with 1324 additions and 857 deletions
|
@ -331,7 +331,7 @@ where
|
|||
.with_failure_code(server::ErrorCode::InternalError)
|
||||
}
|
||||
|
||||
/// Sends back a response to the server using a [`Responder`].
|
||||
/// Sends back a response to the server, but only if the request wasn't cancelled.
|
||||
fn respond<Req>(
|
||||
id: &RequestId,
|
||||
result: Result<<<Req as RequestHandler>::RequestType as Request>::Result>,
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use crate::Session;
|
||||
use crate::server::schedule::Scheduler;
|
||||
use crate::server::{Server, api};
|
||||
use crate::session::client::Client;
|
||||
|
@ -79,7 +78,7 @@ impl Server {
|
|||
.outgoing_mut()
|
||||
.complete(&response.id)
|
||||
{
|
||||
handler(&self.session, response);
|
||||
handler(&client, response);
|
||||
} else {
|
||||
tracing::error!(
|
||||
"Received a response with ID {}, which was not expected",
|
||||
|
@ -203,7 +202,7 @@ impl Server {
|
|||
.unwrap(),
|
||||
),
|
||||
};
|
||||
let response_handler = move |_session: &Session, ()| {
|
||||
let response_handler = move |_: &Client, ()| {
|
||||
tracing::info!("File watcher successfully registered");
|
||||
};
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ impl Pool {
|
|||
|
||||
let threads = usize::from(threads);
|
||||
|
||||
let (job_sender, job_receiver) = crossbeam::channel::bounded(std::cmp::max(threads * 2, 4));
|
||||
let (job_sender, job_receiver) = crossbeam::channel::bounded(std::cmp::min(threads * 2, 4));
|
||||
let extant_tasks = Arc::new(AtomicUsize::new(0));
|
||||
|
||||
let mut handles = Vec::with_capacity(threads);
|
||||
|
|
|
@ -7,7 +7,7 @@ use serde_json::Value;
|
|||
use std::any::TypeId;
|
||||
use std::fmt::Display;
|
||||
|
||||
pub(crate) type ClientResponseHandler = Box<dyn FnOnce(&Session, lsp_server::Response) + Send>;
|
||||
pub(crate) type ClientResponseHandler = Box<dyn FnOnce(&Client, lsp_server::Response) + Send>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Client {
|
||||
|
@ -44,53 +44,51 @@ impl Client {
|
|||
&self,
|
||||
session: &Session,
|
||||
params: R::Params,
|
||||
response_handler: impl FnOnce(&Session, R::Result) + Send + 'static,
|
||||
response_handler: impl FnOnce(&Client, R::Result) + Send + 'static,
|
||||
) -> crate::Result<()>
|
||||
where
|
||||
R: lsp_types::request::Request,
|
||||
{
|
||||
let response_handler = Box::new(
|
||||
move |session: &Session, response: lsp_server::Response| {
|
||||
let _span =
|
||||
tracing::debug_span!("client_response", id=%response.id, method = R::METHOD)
|
||||
.entered();
|
||||
let response_handler = Box::new(move |client: &Client, response: lsp_server::Response| {
|
||||
let _span =
|
||||
tracing::debug_span!("client_response", id=%response.id, method = R::METHOD)
|
||||
.entered();
|
||||
|
||||
match (response.error, response.result) {
|
||||
(Some(err), _) => {
|
||||
match (response.error, response.result) {
|
||||
(Some(err), _) => {
|
||||
tracing::error!(
|
||||
"Got an error from the client (code {code}, method {method}): {message}",
|
||||
code = err.code,
|
||||
message = err.message,
|
||||
method = R::METHOD
|
||||
);
|
||||
}
|
||||
(None, Some(response)) => match serde_json::from_value(response) {
|
||||
Ok(response) => response_handler(client, response),
|
||||
Err(error) => {
|
||||
tracing::error!(
|
||||
"Got an error from the client (code {code}, method {method}): {message}",
|
||||
code = err.code,
|
||||
message = err.message,
|
||||
"Failed to deserialize client response (method={method}): {error}",
|
||||
method = R::METHOD
|
||||
);
|
||||
}
|
||||
(None, Some(response)) => match serde_json::from_value(response) {
|
||||
Ok(response) => response_handler(session, response),
|
||||
Err(error) => {
|
||||
tracing::error!(
|
||||
"Failed to deserialize client response (method={method}): {error}",
|
||||
method = R::METHOD
|
||||
);
|
||||
}
|
||||
},
|
||||
(None, None) => {
|
||||
if TypeId::of::<R::Result>() == TypeId::of::<()>() {
|
||||
// We can't call `response_handler(())` directly here, but
|
||||
// since we _know_ the type expected is `()`, we can use
|
||||
// `from_value(Value::Null)`. `R::Result` implements `DeserializeOwned`,
|
||||
// so this branch works in the general case but we'll only
|
||||
// hit it if the concrete type is `()`, so the `unwrap()` is safe here.
|
||||
response_handler(session, serde_json::from_value(Value::Null).unwrap());
|
||||
} else {
|
||||
tracing::error!(
|
||||
"Invalid client response: did not contain a result or error (method={method})",
|
||||
method = R::METHOD
|
||||
);
|
||||
}
|
||||
},
|
||||
(None, None) => {
|
||||
if TypeId::of::<R::Result>() == TypeId::of::<()>() {
|
||||
// We can't call `response_handler(())` directly here, but
|
||||
// since we _know_ the type expected is `()`, we can use
|
||||
// `from_value(Value::Null)`. `R::Result` implements `DeserializeOwned`,
|
||||
// so this branch works in the general case but we'll only
|
||||
// hit it if the concrete type is `()`, so the `unwrap()` is safe here.
|
||||
response_handler(client, serde_json::from_value(Value::Null).unwrap());
|
||||
} else {
|
||||
tracing::error!(
|
||||
"Invalid client response: did not contain a result or error (method={method})",
|
||||
method = R::METHOD
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
let id = session
|
||||
.request_queue()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue