From 74e08cb60d33e998d89a2a53fcceab48e574045e Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 15 Mar 2023 11:44:35 +0100 Subject: [PATCH] fix: Do not retry inlay hint requests --- crates/rust-analyzer/src/dispatch.rs | 36 +++++++++++++++++++++++++++ crates/rust-analyzer/src/main_loop.rs | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/crates/rust-analyzer/src/dispatch.rs b/crates/rust-analyzer/src/dispatch.rs index 715804449a..313bb2ec8d 100644 --- a/crates/rust-analyzer/src/dispatch.rs +++ b/crates/rust-analyzer/src/dispatch.rs @@ -87,6 +87,42 @@ impl<'a> RequestDispatcher<'a> { self } + /// Dispatches the request onto thread pool + pub(crate) fn on_no_retry( + &mut self, + f: fn(GlobalStateSnapshot, R::Params) -> Result, + ) -> &mut Self + where + R: lsp_types::request::Request + 'static, + R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug, + R::Result: Serialize, + { + let (req, params, panic_context) = match self.parse::() { + Some(it) => it, + None => return self, + }; + + self.global_state.task_pool.handle.spawn({ + let world = self.global_state.snapshot(); + move || { + let result = panic::catch_unwind(move || { + let _pctx = stdx::panic_context::enter(panic_context); + f(world, params) + }); + match thread_result_to_response::(req.id.clone(), result) { + Ok(response) => Task::Response(response), + Err(_) => Task::Response(lsp_server::Response::new_err( + req.id, + lsp_server::ErrorCode::ContentModified as i32, + "content modified".to_string(), + )), + } + } + }); + + self + } + /// Dispatches the request onto thread pool pub(crate) fn on( &mut self, diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index dd0804b439..939d3ac3e7 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -653,7 +653,7 @@ impl GlobalState { .on::(handlers::handle_goto_declaration) .on::(handlers::handle_goto_implementation) .on::(handlers::handle_goto_type_definition) - .on::(handlers::handle_inlay_hints) + .on_no_retry::(handlers::handle_inlay_hints) .on::(handlers::handle_inlay_hints_resolve) .on::(handlers::handle_completion) .on::(handlers::handle_completion_resolve)