Skip to content

Commit

Permalink
Auto merge of rust-lang#13202 - Veykril:cancelled-retry, r=Veykril
Browse files Browse the repository at this point in the history
Don't retry requests that have already been cancelled
  • Loading branch information
bors committed Sep 27, 2022
2 parents b16b041 + 1a6c159 commit 9ba55ba
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ threadpool = "1.8.1"
rayon = "1.5.3"
num_cpus = "1.13.1"
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-subscriber = { version = "0.3.14", default-features = false, features = [
"env-filter",
Expand Down
4 changes: 4 additions & 0 deletions crates/rust-analyzer/src/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ impl GlobalState {
}
}

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) {
self.sender.send(message).unwrap()
}
Expand Down
4 changes: 3 additions & 1 deletion crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ impl GlobalState {
fn handle_task(&mut self, prime_caches_progress: &mut Vec<PrimeCachesProgress>, task: Task) {
match task {
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) => {
for (file_id, diagnostics) in diagnostics_per_file {
self.diagnostics.set_native_diagnostics(file_id, diagnostics)
Expand Down
10 changes: 5 additions & 5 deletions lib/lsp-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
name = "lsp-server"
version = "0.6.0"
version = "0.7.0"
description = "Generic LSP server scaffold."
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/rust-analyzer/tree/master/lib/lsp-server"
edition = "2021"

[dependencies]
log = "0.4.17"
serde_json = "1.0.81"
serde = { version = "1.0.137", features = ["derive"] }
crossbeam-channel = "0.5.5"
serde_json = "1.0.85"
serde = { version = "1.0.144", features = ["derive"] }
crossbeam-channel = "0.5.6"

[dev-dependencies]
lsp-types = "0.93.0"
lsp-types = "0.93.1"
2 changes: 1 addition & 1 deletion lib/lsp-server/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub struct ResponseError {
}

#[derive(Clone, Copy, Debug)]
#[allow(unused)]
#[non_exhaustive]
pub enum ErrorCode {
// Defined by JSON RPC:
ParseError = -32700,
Expand Down
7 changes: 7 additions & 0 deletions lib/lsp-server/src/req_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl<I> Incoming<I> {
pub fn register(&mut self, id: RequestId, data: I) {
self.pending.insert(id, data);
}

pub fn cancel(&mut self, id: RequestId) -> Option<Response> {
let _data = self.complete(id.clone())?;
let error = ResponseError {
Expand All @@ -44,9 +45,14 @@ impl<I> Incoming<I> {
};
Some(Response { id, result: None, error: Some(error) })
}

pub fn complete(&mut self, id: RequestId) -> Option<I> {
self.pending.remove(&id)
}

pub fn is_completed(&self, id: &RequestId) -> bool {
!self.pending.contains_key(id)
}
}

impl<O> Outgoing<O> {
Expand All @@ -56,6 +62,7 @@ impl<O> Outgoing<O> {
self.next_id += 1;
Request::new(id, method, params)
}

pub fn complete(&mut self, id: RequestId) -> Option<O> {
self.pending.remove(&id)
}
Expand Down

0 comments on commit 9ba55ba

Please sign in to comment.