Skip to content

Commit b7db9f0

Browse files
committed
Apply suggestions from code review
1 parent 9b4256d commit b7db9f0

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

crates/ra_ide/src/hover.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::{
1717
runnables::runnable,
1818
FileId, FilePosition, NavigationTarget, RangeInfo, Runnable,
1919
};
20+
use test_utils::mark;
2021

2122
#[derive(Clone, Debug, PartialEq, Eq)]
2223
pub struct HoverConfig {
@@ -202,10 +203,9 @@ fn runnable_action(
202203
ModuleDef::Function(it) => {
203204
let src = it.source(sema.db);
204205
if src.file_id != file_id.into() {
205-
// Don't try to find runnables in a macro generated code.
206-
// See tests below:
207-
// test_hover_macro_generated_struct_fn_doc_comment
208-
// test_hover_macro_generated_struct_fn_doc_attr
206+
mark::hit!(hover_macro_generated_struct_fn_doc_comment);
207+
mark::hit!(hover_macro_generated_struct_fn_doc_attr);
208+
209209
return None;
210210
}
211211

@@ -1121,6 +1121,8 @@ fn func(foo: i32) { if true { <|>foo; }; }
11211121

11221122
#[test]
11231123
fn test_hover_macro_generated_struct_fn_doc_comment() {
1124+
mark::check!(hover_macro_generated_struct_fn_doc_comment);
1125+
11241126
check_hover_result(
11251127
r#"
11261128
//- /lib.rs
@@ -1147,6 +1149,8 @@ fn func(foo: i32) { if true { <|>foo; }; }
11471149

11481150
#[test]
11491151
fn test_hover_macro_generated_struct_fn_doc_attr() {
1152+
mark::check!(hover_macro_generated_struct_fn_doc_attr);
1153+
11501154
check_hover_result(
11511155
r#"
11521156
//- /lib.rs

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ pub fn handle_runnables(
408408
continue;
409409
}
410410

411-
res.push(to_proto::runnable(&snap, file_id, &runnable)?);
411+
res.push(to_proto::runnable(&snap, file_id, runnable)?);
412412
}
413413

414414
// Add `cargo check` and `cargo test` for the whole package
@@ -818,7 +818,7 @@ pub fn handle_code_lens(
818818

819819
let action = runnable.action();
820820
let range = to_proto::range(&line_index, runnable.nav.range());
821-
let r = to_proto::runnable(&snap, file_id, &runnable)?;
821+
let r = to_proto::runnable(&snap, file_id, runnable)?;
822822
if snap.config.lens.run {
823823
let lens = CodeLens {
824824
range,
@@ -830,7 +830,7 @@ pub fn handle_code_lens(
830830

831831
if action.debugee && snap.config.lens.debug {
832832
let debug_lens =
833-
CodeLens { range, command: Some(debug_single_command(r)), data: None };
833+
CodeLens { range, command: Some(debug_single_command(&r)), data: None };
834834
lenses.push(debug_lens);
835835
}
836836
}
@@ -1142,7 +1142,7 @@ fn run_single_command(runnable: &lsp_ext::Runnable, title: &str) -> Command {
11421142
}
11431143
}
11441144

1145-
fn debug_single_command(runnable: lsp_ext::Runnable) -> Command {
1145+
fn debug_single_command(runnable: &lsp_ext::Runnable) -> Command {
11461146
Command {
11471147
title: "Debug".into(),
11481148
command: "rust-analyzer.debugSingle".into(),
@@ -1183,26 +1183,25 @@ fn show_impl_command_link(
11831183
fn to_runnable_action(
11841184
snap: &GlobalStateSnapshot,
11851185
file_id: FileId,
1186-
runnable: &Runnable,
1186+
runnable: Runnable,
11871187
) -> Option<lsp_ext::CommandLinkGroup> {
11881188
let cargo_spec = CargoTargetSpec::for_file(&snap, file_id).ok()?;
1189-
if should_skip_target(runnable, cargo_spec.as_ref()) {
1189+
if should_skip_target(&runnable, cargo_spec.as_ref()) {
11901190
return None;
11911191
}
11921192

1193+
let action: &'static _ = runnable.action();
11931194
to_proto::runnable(snap, file_id, runnable).ok().map(|r| {
11941195
let mut group = lsp_ext::CommandLinkGroup::default();
11951196

1196-
let action = runnable.action();
11971197
if snap.config.hover.run {
11981198
let run_command = run_single_command(&r, action.run_title);
11991199
group.commands.push(to_command_link(run_command, r.label.clone()));
12001200
}
12011201

12021202
if snap.config.hover.debug {
1203-
let hint = r.label.clone();
1204-
let dbg_command = debug_single_command(r);
1205-
group.commands.push(to_command_link(dbg_command, hint));
1203+
let dbg_command = debug_single_command(&r);
1204+
group.commands.push(to_command_link(dbg_command, r.label));
12061205
}
12071206

12081207
group
@@ -1222,7 +1221,7 @@ fn prepare_hover_actions(
12221221
.iter()
12231222
.filter_map(|it| match it {
12241223
HoverAction::Implementaion(position) => show_impl_command_link(snap, position),
1225-
HoverAction::Runnable(r) => to_runnable_action(snap, file_id, r),
1224+
HoverAction::Runnable(r) => to_runnable_action(snap, file_id, r.clone()),
12261225
})
12271226
.collect()
12281227
}
@@ -1232,10 +1231,7 @@ fn should_skip_target(runnable: &Runnable, cargo_spec: Option<&CargoTargetSpec>)
12321231
RunnableKind::Bin => {
12331232
// Do not suggest binary run on other target than binary
12341233
match &cargo_spec {
1235-
Some(spec) => match spec.target_kind {
1236-
TargetKind::Bin => false,
1237-
_ => true,
1238-
},
1234+
Some(spec) => spec.target_kind != TargetKind::Bin,
12391235
None => true,
12401236
}
12411237
}

crates/rust-analyzer/src/to_proto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,14 +656,14 @@ pub(crate) fn resolved_code_action(
656656
pub(crate) fn runnable(
657657
snap: &GlobalStateSnapshot,
658658
file_id: FileId,
659-
runnable: &Runnable,
659+
runnable: Runnable,
660660
) -> Result<lsp_ext::Runnable> {
661661
let spec = CargoTargetSpec::for_file(snap, file_id)?;
662662
let target = spec.as_ref().map(|s| s.target.clone());
663663
let (cargo_args, executable_args) =
664664
CargoTargetSpec::runnable_args(spec, &runnable.kind, &runnable.cfg_exprs)?;
665665
let label = runnable.label(target);
666-
let location = location_link(snap, None, runnable.nav.clone())?;
666+
let location = location_link(snap, None, runnable.nav)?;
667667

668668
Ok(lsp_ext::Runnable {
669669
label,

0 commit comments

Comments
 (0)