Auto merge of #13202 - Veykril:cancelled-retry, r=Veykril

Don't retry requests that have already been cancelled
This commit is contained in:
bors 2022-09-27 15:43:57 +00:00
commit 9ba55bad4f
7 changed files with 28 additions and 15 deletions

14
Cargo.lock generated
View File

@ -863,7 +863,7 @@ dependencies = [
[[package]] [[package]]
name = "lsp-server" name = "lsp-server"
version = "0.6.0" version = "0.7.0"
dependencies = [ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"log", "log",
@ -1502,18 +1502,18 @@ dependencies = [
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.143" version = "1.0.144"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553" checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.143" version = "1.0.144"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3d8e8de557aee63c26b85b947f5e59b690d0454c753f3adeb5cd7835ab88391" checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1522,9 +1522,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.83" version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"itoa", "itoa",

View File

@ -34,7 +34,7 @@ threadpool = "1.8.1"
rayon = "1.5.3" rayon = "1.5.3"
num_cpus = "1.13.1" num_cpus = "1.13.1"
mimalloc = { version = "0.1.29", default-features = false, optional = true } mimalloc = { version = "0.1.29", default-features = false, optional = true }
lsp-server = { version = "0.6.0", path = "../../lib/lsp-server" } lsp-server = { version = "0.7.0", path = "../../lib/lsp-server" }
tracing = "0.1.35" tracing = "0.1.35"
tracing-subscriber = { version = "0.3.14", default-features = false, features = [ tracing-subscriber = { version = "0.3.14", default-features = false, features = [
"env-filter", "env-filter",

View File

@ -354,6 +354,10 @@ pub(crate) fn cancel(&mut self, request_id: lsp_server::RequestId) {
} }
} }
pub(crate) fn is_completed(&self, request: &lsp_server::Request) -> bool {
self.req_queue.incoming.is_completed(&request.id)
}
fn send(&mut self, message: lsp_server::Message) { fn send(&mut self, message: lsp_server::Message) {
self.sender.send(message).unwrap() self.sender.send(message).unwrap()
} }

View File

@ -425,7 +425,9 @@ fn handle_event(&mut self, event: Event) -> Result<()> {
fn handle_task(&mut self, prime_caches_progress: &mut Vec<PrimeCachesProgress>, task: Task) { fn handle_task(&mut self, prime_caches_progress: &mut Vec<PrimeCachesProgress>, task: Task) {
match task { match task {
Task::Response(response) => self.respond(response), Task::Response(response) => self.respond(response),
Task::Retry(req) => self.on_request(req), // Only retry requests that haven't been cancelled. Otherwise we do unnecessary work.
Task::Retry(req) if self.is_completed(&req) => self.on_request(req),
Task::Retry(_) => (),
Task::Diagnostics(diagnostics_per_file) => { Task::Diagnostics(diagnostics_per_file) => {
for (file_id, diagnostics) in diagnostics_per_file { for (file_id, diagnostics) in diagnostics_per_file {
self.diagnostics.set_native_diagnostics(file_id, diagnostics) self.diagnostics.set_native_diagnostics(file_id, diagnostics)

View File

@ -1,6 +1,6 @@
[package] [package]
name = "lsp-server" name = "lsp-server"
version = "0.6.0" version = "0.7.0"
description = "Generic LSP server scaffold." description = "Generic LSP server scaffold."
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/rust-analyzer/tree/master/lib/lsp-server" repository = "https://github.com/rust-lang/rust-analyzer/tree/master/lib/lsp-server"
@ -8,9 +8,9 @@ edition = "2021"
[dependencies] [dependencies]
log = "0.4.17" log = "0.4.17"
serde_json = "1.0.81" serde_json = "1.0.85"
serde = { version = "1.0.137", features = ["derive"] } serde = { version = "1.0.144", features = ["derive"] }
crossbeam-channel = "0.5.5" crossbeam-channel = "0.5.6"
[dev-dependencies] [dev-dependencies]
lsp-types = "0.93.0" lsp-types = "0.93.1"

View File

@ -98,7 +98,7 @@ pub struct ResponseError {
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
#[allow(unused)] #[non_exhaustive]
pub enum ErrorCode { pub enum ErrorCode {
// Defined by JSON RPC: // Defined by JSON RPC:
ParseError = -32700, ParseError = -32700,

View File

@ -35,6 +35,7 @@ impl<I> Incoming<I> {
pub fn register(&mut self, id: RequestId, data: I) { pub fn register(&mut self, id: RequestId, data: I) {
self.pending.insert(id, data); self.pending.insert(id, data);
} }
pub fn cancel(&mut self, id: RequestId) -> Option<Response> { pub fn cancel(&mut self, id: RequestId) -> Option<Response> {
let _data = self.complete(id.clone())?; let _data = self.complete(id.clone())?;
let error = ResponseError { let error = ResponseError {
@ -44,9 +45,14 @@ pub fn cancel(&mut self, id: RequestId) -> Option<Response> {
}; };
Some(Response { id, result: None, error: Some(error) }) Some(Response { id, result: None, error: Some(error) })
} }
pub fn complete(&mut self, id: RequestId) -> Option<I> { pub fn complete(&mut self, id: RequestId) -> Option<I> {
self.pending.remove(&id) self.pending.remove(&id)
} }
pub fn is_completed(&self, id: &RequestId) -> bool {
!self.pending.contains_key(id)
}
} }
impl<O> Outgoing<O> { impl<O> Outgoing<O> {
@ -56,6 +62,7 @@ pub fn register<P: Serialize>(&mut self, method: String, params: P, data: O) ->
self.next_id += 1; self.next_id += 1;
Request::new(id, method, params) Request::new(id, method, params)
} }
pub fn complete(&mut self, id: RequestId) -> Option<O> { pub fn complete(&mut self, id: RequestId) -> Option<O> {
self.pending.remove(&id) self.pending.remove(&id)
} }