aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorvsrs <[email protected]>2020-06-08 11:56:31 +0100
committervsrs <[email protected]>2020-06-08 12:19:40 +0100
commitb7db9f058ad51b7ba47db02b581a76b6756d74e8 (patch)
tree414a4bdea9d429df53648fcd5e6d0002d9c0d8fd /crates
parent9b4256dc4d9e0b633b73f5c07e6e0721bc1e9108 (diff)
Apply suggestions from code review
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/hover.rs12
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs26
-rw-r--r--crates/rust-analyzer/src/to_proto.rs4
3 files changed, 21 insertions, 21 deletions
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index bbff5e81a..ad78b7671 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -17,6 +17,7 @@ use crate::{
17 runnables::runnable, 17 runnables::runnable,
18 FileId, FilePosition, NavigationTarget, RangeInfo, Runnable, 18 FileId, FilePosition, NavigationTarget, RangeInfo, Runnable,
19}; 19};
20use test_utils::mark;
20 21
21#[derive(Clone, Debug, PartialEq, Eq)] 22#[derive(Clone, Debug, PartialEq, Eq)]
22pub struct HoverConfig { 23pub struct HoverConfig {
@@ -202,10 +203,9 @@ fn runnable_action(
202 ModuleDef::Function(it) => { 203 ModuleDef::Function(it) => {
203 let src = it.source(sema.db); 204 let src = it.source(sema.db);
204 if src.file_id != file_id.into() { 205 if src.file_id != file_id.into() {
205 // Don't try to find runnables in a macro generated code. 206 mark::hit!(hover_macro_generated_struct_fn_doc_comment);
206 // See tests below: 207 mark::hit!(hover_macro_generated_struct_fn_doc_attr);
207 // test_hover_macro_generated_struct_fn_doc_comment 208
208 // test_hover_macro_generated_struct_fn_doc_attr
209 return None; 209 return None;
210 } 210 }
211 211
@@ -1121,6 +1121,8 @@ fn func(foo: i32) { if true { <|>foo; }; }
1121 1121
1122 #[test] 1122 #[test]
1123 fn test_hover_macro_generated_struct_fn_doc_comment() { 1123 fn test_hover_macro_generated_struct_fn_doc_comment() {
1124 mark::check!(hover_macro_generated_struct_fn_doc_comment);
1125
1124 check_hover_result( 1126 check_hover_result(
1125 r#" 1127 r#"
1126 //- /lib.rs 1128 //- /lib.rs
@@ -1147,6 +1149,8 @@ fn func(foo: i32) { if true { <|>foo; }; }
1147 1149
1148 #[test] 1150 #[test]
1149 fn test_hover_macro_generated_struct_fn_doc_attr() { 1151 fn test_hover_macro_generated_struct_fn_doc_attr() {
1152 mark::check!(hover_macro_generated_struct_fn_doc_attr);
1153
1150 check_hover_result( 1154 check_hover_result(
1151 r#" 1155 r#"
1152 //- /lib.rs 1156 //- /lib.rs
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index eaa43f2bd..a41adf8b0 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -408,7 +408,7 @@ pub fn handle_runnables(
408 continue; 408 continue;
409 } 409 }
410 410
411 res.push(to_proto::runnable(&snap, file_id, &runnable)?); 411 res.push(to_proto::runnable(&snap, file_id, runnable)?);
412 } 412 }
413 413
414 // Add `cargo check` and `cargo test` for the whole package 414 // Add `cargo check` and `cargo test` for the whole package
@@ -818,7 +818,7 @@ pub fn handle_code_lens(
818 818
819 let action = runnable.action(); 819 let action = runnable.action();
820 let range = to_proto::range(&line_index, runnable.nav.range()); 820 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)?;
822 if snap.config.lens.run { 822 if snap.config.lens.run {
823 let lens = CodeLens { 823 let lens = CodeLens {
824 range, 824 range,
@@ -830,7 +830,7 @@ pub fn handle_code_lens(
830 830
831 if action.debugee && snap.config.lens.debug { 831 if action.debugee && snap.config.lens.debug {
832 let debug_lens = 832 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 };
834 lenses.push(debug_lens); 834 lenses.push(debug_lens);
835 } 835 }
836 } 836 }
@@ -1142,7 +1142,7 @@ fn run_single_command(runnable: &lsp_ext::Runnable, title: &str) -> Command {
1142 } 1142 }
1143} 1143}
1144 1144
1145fn debug_single_command(runnable: lsp_ext::Runnable) -> Command { 1145fn debug_single_command(runnable: &lsp_ext::Runnable) -> Command {
1146 Command { 1146 Command {
1147 title: "Debug".into(), 1147 title: "Debug".into(),
1148 command: "rust-analyzer.debugSingle".into(), 1148 command: "rust-analyzer.debugSingle".into(),
@@ -1183,26 +1183,25 @@ fn show_impl_command_link(
1183fn to_runnable_action( 1183fn to_runnable_action(
1184 snap: &GlobalStateSnapshot, 1184 snap: &GlobalStateSnapshot,
1185 file_id: FileId, 1185 file_id: FileId,
1186 runnable: &Runnable, 1186 runnable: Runnable,
1187) -> Option<lsp_ext::CommandLinkGroup> { 1187) -> Option<lsp_ext::CommandLinkGroup> {
1188 let cargo_spec = CargoTargetSpec::for_file(&snap, file_id).ok()?; 1188 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()) {
1190 return None; 1190 return None;
1191 } 1191 }
1192 1192
1193 let action: &'static _ = runnable.action();
1193 to_proto::runnable(snap, file_id, runnable).ok().map(|r| { 1194 to_proto::runnable(snap, file_id, runnable).ok().map(|r| {
1194 let mut group = lsp_ext::CommandLinkGroup::default(); 1195 let mut group = lsp_ext::CommandLinkGroup::default();
1195 1196
1196 let action = runnable.action();
1197 if snap.config.hover.run { 1197 if snap.config.hover.run {
1198 let run_command = run_single_command(&r, action.run_title); 1198 let run_command = run_single_command(&r, action.run_title);
1199 group.commands.push(to_command_link(run_command, r.label.clone())); 1199 group.commands.push(to_command_link(run_command, r.label.clone()));
1200 } 1200 }
1201 1201
1202 if snap.config.hover.debug { 1202 if snap.config.hover.debug {
1203 let hint = r.label.clone(); 1203 let dbg_command = debug_single_command(&r);
1204 let dbg_command = debug_single_command(r); 1204 group.commands.push(to_command_link(dbg_command, r.label));
1205 group.commands.push(to_command_link(dbg_command, hint));
1206 } 1205 }
1207 1206
1208 group 1207 group
@@ -1222,7 +1221,7 @@ fn prepare_hover_actions(
1222 .iter() 1221 .iter()
1223 .filter_map(|it| match it { 1222 .filter_map(|it| match it {
1224 HoverAction::Implementaion(position) => show_impl_command_link(snap, position), 1223 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()),
1226 }) 1225 })
1227 .collect() 1226 .collect()
1228} 1227}
@@ -1232,10 +1231,7 @@ fn should_skip_target(runnable: &Runnable, cargo_spec: Option<&CargoTargetSpec>)
1232 RunnableKind::Bin => { 1231 RunnableKind::Bin => {
1233 // Do not suggest binary run on other target than binary 1232 // Do not suggest binary run on other target than binary
1234 match &cargo_spec { 1233 match &cargo_spec {
1235 Some(spec) => match spec.target_kind { 1234 Some(spec) => spec.target_kind != TargetKind::Bin,
1236 TargetKind::Bin => false,
1237 _ => true,
1238 },
1239 None => true, 1235 None => true,
1240 } 1236 }
1241 } 1237 }
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 5daf037da..710df1fbd 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -656,14 +656,14 @@ pub(crate) fn resolved_code_action(
656pub(crate) fn runnable( 656pub(crate) fn runnable(
657 snap: &GlobalStateSnapshot, 657 snap: &GlobalStateSnapshot,
658 file_id: FileId, 658 file_id: FileId,
659 runnable: &Runnable, 659 runnable: Runnable,
660) -> Result<lsp_ext::Runnable> { 660) -> Result<lsp_ext::Runnable> {
661 let spec = CargoTargetSpec::for_file(snap, file_id)?; 661 let spec = CargoTargetSpec::for_file(snap, file_id)?;
662 let target = spec.as_ref().map(|s| s.target.clone()); 662 let target = spec.as_ref().map(|s| s.target.clone());
663 let (cargo_args, executable_args) = 663 let (cargo_args, executable_args) =
664 CargoTargetSpec::runnable_args(spec, &runnable.kind, &runnable.cfg_exprs)?; 664 CargoTargetSpec::runnable_args(spec, &runnable.kind, &runnable.cfg_exprs)?;
665 let label = runnable.label(target); 665 let label = runnable.label(target);
666 let location = location_link(snap, None, runnable.nav.clone())?; 666 let location = location_link(snap, None, runnable.nav)?;
667 667
668 Ok(lsp_ext::Runnable { 668 Ok(lsp_ext::Runnable {
669 label, 669 label,