Skip to content

Commit 57cd0d5

Browse files
committed
feat: support UpdateTest in hover actions and runnables
1 parent edb61b1 commit 57cd0d5

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

crates/rust-analyzer/src/handlers/request.rs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use paths::Utf8PathBuf;
3232
use project_model::{CargoWorkspace, ManifestPath, ProjectWorkspaceKind, TargetKind};
3333
use serde_json::json;
3434
use stdx::{format_to, never};
35-
use syntax::{algo, ast, AstNode, TextRange, TextSize};
35+
use syntax::{TextRange, TextSize};
3636
use triomphe::Arc;
3737
use vfs::{AbsPath, AbsPathBuf, FileId, VfsPath};
3838

@@ -933,39 +933,31 @@ pub(crate) fn handle_runnables(
933933
let offset = params.position.and_then(|it| from_proto::offset(&line_index, it).ok());
934934
let target_spec = TargetSpec::for_file(&snap, file_id)?;
935935

936-
let expect_test = match offset {
937-
Some(offset) => {
938-
let source_file = snap.analysis.parse(file_id)?;
939-
algo::find_node_at_offset::<ast::MacroCall>(source_file.syntax(), offset)
940-
.and_then(|it| it.path()?.segment()?.name_ref())
941-
.map_or(false, |it| it.text() == "expect" || it.text() == "expect_file")
942-
}
943-
None => false,
944-
};
945-
946936
let mut res = Vec::new();
947937
for runnable in snap.analysis.runnables(file_id)? {
948-
if should_skip_for_offset(&runnable, offset) {
949-
continue;
950-
}
951-
if should_skip_target(&runnable, target_spec.as_ref()) {
938+
if should_skip_for_offset(&runnable, offset)
939+
|| should_skip_target(&runnable, target_spec.as_ref())
940+
{
952941
continue;
953942
}
943+
944+
let update_test = runnable.update_test;
954945
if let Some(mut runnable) = to_proto::runnable(&snap, runnable)? {
955-
if expect_test {
956-
if let lsp_ext::RunnableArgs::Cargo(r) = &mut runnable.args {
957-
runnable.label = format!("{} + expect", runnable.label);
958-
r.environment.insert("UPDATE_EXPECT".to_owned(), "1".to_owned());
959-
if let Some(TargetSpec::Cargo(CargoTargetSpec {
960-
sysroot_root: Some(sysroot_root),
961-
..
962-
})) = &target_spec
963-
{
964-
r.environment
965-
.insert("RUSTC_TOOLCHAIN".to_owned(), sysroot_root.to_string());
966-
}
967-
}
946+
if let Some(runnable) = to_proto::make_update_runnable(&runnable, &update_test.label())
947+
{
948+
res.push(runnable);
968949
}
950+
951+
if let lsp_ext::RunnableArgs::Cargo(r) = &mut runnable.args {
952+
if let Some(TargetSpec::Cargo(CargoTargetSpec {
953+
sysroot_root: Some(sysroot_root),
954+
..
955+
})) = &target_spec
956+
{
957+
r.environment.insert("RUSTC_TOOLCHAIN".to_owned(), sysroot_root.to_string());
958+
}
959+
};
960+
969961
res.push(runnable);
970962
}
971963
}
@@ -2143,11 +2135,15 @@ fn runnable_action_links(
21432135
}
21442136

21452137
let client_commands_config = snap.config.client_commands();
2146-
if !(client_commands_config.run_single || client_commands_config.debug_single) {
2138+
if !(client_commands_config.run_single
2139+
|| client_commands_config.debug_single
2140+
|| client_commands_config.update_single)
2141+
{
21472142
return None;
21482143
}
21492144

21502145
let title = runnable.title();
2146+
let update_test = runnable.update_test;
21512147
let r = to_proto::runnable(snap, runnable).ok()??;
21522148

21532149
let mut group = lsp_ext::CommandLinkGroup::default();
@@ -2159,7 +2155,13 @@ fn runnable_action_links(
21592155

21602156
if hover_actions_config.debug && client_commands_config.debug_single {
21612157
let dbg_command = to_proto::command::debug_single(&r);
2162-
group.commands.push(to_command_link(dbg_command, r.label));
2158+
group.commands.push(to_command_link(dbg_command, r.label.clone()));
2159+
}
2160+
2161+
if client_commands_config.update_single {
2162+
if let Some(update_command) = to_proto::command::update_single(&r, &update_test.label()) {
2163+
group.commands.push(to_command_link(update_command, r.label.clone()));
2164+
}
21632165
}
21642166

21652167
Some(group)

0 commit comments

Comments
 (0)