Skip to content

Commit adbda94

Browse files
committed
Auto merge of rust-lang#14359 - Veykril:opt-out-retry, r=Veykril
fix: Do not retry inlay hint requests Should close rust-lang/rust-analyzer#13372, retrying the way its currently implemented is not ideal as we do not adjust offsets in the requests, but doing that is a major PITA, so this should at least work around one of the more annoying issues stemming from it.
2 parents 1787c14 + 74e08cb commit adbda94

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

crates/rust-analyzer/src/dispatch.rs

+36
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,42 @@ impl<'a> RequestDispatcher<'a> {
8787
self
8888
}
8989

90+
/// Dispatches the request onto thread pool
91+
pub(crate) fn on_no_retry<R>(
92+
&mut self,
93+
f: fn(GlobalStateSnapshot, R::Params) -> Result<R::Result>,
94+
) -> &mut Self
95+
where
96+
R: lsp_types::request::Request + 'static,
97+
R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug,
98+
R::Result: Serialize,
99+
{
100+
let (req, params, panic_context) = match self.parse::<R>() {
101+
Some(it) => it,
102+
None => return self,
103+
};
104+
105+
self.global_state.task_pool.handle.spawn({
106+
let world = self.global_state.snapshot();
107+
move || {
108+
let result = panic::catch_unwind(move || {
109+
let _pctx = stdx::panic_context::enter(panic_context);
110+
f(world, params)
111+
});
112+
match thread_result_to_response::<R>(req.id.clone(), result) {
113+
Ok(response) => Task::Response(response),
114+
Err(_) => Task::Response(lsp_server::Response::new_err(
115+
req.id,
116+
lsp_server::ErrorCode::ContentModified as i32,
117+
"content modified".to_string(),
118+
)),
119+
}
120+
}
121+
});
122+
123+
self
124+
}
125+
90126
/// Dispatches the request onto thread pool
91127
pub(crate) fn on<R>(
92128
&mut self,

crates/rust-analyzer/src/main_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ impl GlobalState {
663663
.on::<lsp_types::request::GotoDeclaration>(handlers::handle_goto_declaration)
664664
.on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation)
665665
.on::<lsp_types::request::GotoTypeDefinition>(handlers::handle_goto_type_definition)
666-
.on::<lsp_types::request::InlayHintRequest>(handlers::handle_inlay_hints)
666+
.on_no_retry::<lsp_types::request::InlayHintRequest>(handlers::handle_inlay_hints)
667667
.on::<lsp_types::request::InlayHintResolveRequest>(handlers::handle_inlay_hints_resolve)
668668
.on::<lsp_types::request::Completion>(handlers::handle_completion)
669669
.on::<lsp_types::request::ResolveCompletionItem>(handlers::handle_completion_resolve)

0 commit comments

Comments
 (0)