From 3315750361cbbade0df709209477bce7eaa5d1d9 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 16 Feb 2022 17:34:23 -0800 Subject: [PATCH] Remove waiting for edits when handling code action RPC requests Add code actions to the randomized integration test Co-Authored-By: Nathan Sobo --- crates/project/src/project.rs | 9 ++++----- crates/server/src/rpc.rs | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index aa72bcc547..9dde473377 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -2433,11 +2433,10 @@ impl Project { .and_then(|shared_buffers| shared_buffers.get(&envelope.payload.buffer_id).cloned()) .ok_or_else(|| anyhow!("unknown buffer id {}", envelope.payload.buffer_id)) })?; - buffer - .update(&mut cx, |buffer, _| { - buffer.wait_for_version([start.timestamp, end.timestamp].into_iter().collect()) - }) - .await; + let version = buffer.read_with(&cx, |buffer, _| buffer.version()); + if !version.observed(start.timestamp) || !version.observed(end.timestamp) { + Err(anyhow!("code action request references unreceived edits"))?; + } let code_actions = this.update(&mut cx, |this, cx| { Ok::<_, anyhow::Error>(this.code_actions(&buffer, start..end, cx)) })?; diff --git a/crates/server/src/rpc.rs b/crates/server/src/rpc.rs index 971ae391b9..e0b919a50e 100644 --- a/crates/server/src/rpc.rs +++ b/crates/server/src/rpc.rs @@ -3622,6 +3622,15 @@ mod tests { ..Default::default() }])) }); + + fake_server.handle_request::(|_| { + Some(vec![lsp::CodeActionOrCommand::CodeAction( + lsp::CodeAction { + title: "the-code-action".to_string(), + ..Default::default() + }, + )]) + }); }); Arc::get_mut(&mut host_lang_registry) @@ -4180,7 +4189,7 @@ mod tests { drop(buffer); }); } - 10..=19 => { + 10..=14 => { project .update(&mut cx, |project, cx| { log::info!( @@ -4193,6 +4202,19 @@ mod tests { .await .expect("completion request failed"); } + 15..=19 => { + project + .update(&mut cx, |project, cx| { + log::info!( + "Guest {}: requesting code actions for buffer {:?}", + guest_id, + buffer.read(cx).file().unwrap().full_path(cx) + ); + project.code_actions(&buffer, 0..0, cx) + }) + .await + .expect("completion request failed"); + } _ => { buffer.update(&mut cx, |buffer, cx| { log::info!(