diff options
Diffstat (limited to 'crates/rust-analyzer/src/main_loop/handlers.rs')
-rw-r--r-- | crates/rust-analyzer/src/main_loop/handlers.rs | 86 |
1 files changed, 42 insertions, 44 deletions
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index 3ff779702..da16976d3 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs | |||
@@ -18,7 +18,7 @@ use lsp_types::{ | |||
18 | TextDocumentIdentifier, Url, WorkspaceEdit, | 18 | TextDocumentIdentifier, Url, WorkspaceEdit, |
19 | }; | 19 | }; |
20 | use ra_ide::{ | 20 | use ra_ide::{ |
21 | FileId, FilePosition, FileRange, HoverAction, Query, RangeInfo, RunnableKind, SearchScope, | 21 | FileId, FilePosition, FileRange, HoverAction, Query, RangeInfo, Runnable, RunnableKind, SearchScope, |
22 | TextEdit, | 22 | TextEdit, |
23 | }; | 23 | }; |
24 | use ra_prof::profile; | 24 | use ra_prof::profile; |
@@ -403,16 +403,11 @@ pub fn handle_runnables( | |||
403 | if !runnable.nav.full_range().contains_inclusive(offset) { | 403 | if !runnable.nav.full_range().contains_inclusive(offset) { |
404 | continue; | 404 | continue; |
405 | } | 405 | } |
406 | } | ||
407 | if is_lib_target(&runnable, cargo_spec.as_ref()) { | ||
408 | continue; | ||
406 | } | 409 | } |
407 | // Do not suggest binary run on other target than binary | 410 | |
408 | if let RunnableKind::Bin = runnable.kind { | ||
409 | if let Some(spec) = &cargo_spec { | ||
410 | match spec.target_kind { | ||
411 | TargetKind::Bin => {} | ||
412 | _ => continue, | ||
413 | } | ||
414 | } | ||
415 | } | ||
416 | res.push(to_proto::runnable(&snap, file_id, runnable)?); | 411 | res.push(to_proto::runnable(&snap, file_id, runnable)?); |
417 | } | 412 | } |
418 | 413 | ||
@@ -817,53 +812,26 @@ pub fn handle_code_lens( | |||
817 | if snap.config.lens.runnable() { | 812 | if snap.config.lens.runnable() { |
818 | // Gather runnables | 813 | // Gather runnables |
819 | for runnable in snap.analysis().runnables(file_id)? { | 814 | for runnable in snap.analysis().runnables(file_id)? { |
820 | let (run_title, debugee) = match &runnable.kind { | 815 | if is_lib_target(&runnable, cargo_spec.as_ref()) { |
821 | RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => { | 816 | continue; |
822 | ("▶\u{fe0e} Run Test", true) | 817 | } |
823 | } | ||
824 | RunnableKind::DocTest { .. } => { | ||
825 | // cargo does not support -no-run for doctests | ||
826 | ("▶\u{fe0e} Run Doctest", false) | ||
827 | } | ||
828 | RunnableKind::Bench { .. } => { | ||
829 | // Nothing wrong with bench debugging | ||
830 | ("Run Bench", true) | ||
831 | } | ||
832 | RunnableKind::Bin => { | ||
833 | // Do not suggest binary run on other target than binary | ||
834 | match &cargo_spec { | ||
835 | Some(spec) => match spec.target_kind { | ||
836 | TargetKind::Bin => ("Run", true), | ||
837 | _ => continue, | ||
838 | }, | ||
839 | None => continue, | ||
840 | } | ||
841 | } | ||
842 | }; | ||
843 | 818 | ||
819 | let action = runnable.action(); | ||
844 | let range = to_proto::range(&line_index, runnable.nav.range()); | 820 | let range = to_proto::range(&line_index, runnable.nav.range()); |
845 | let r = to_proto::runnable(&snap, file_id, runnable)?; | 821 | let r = to_proto::runnable(&snap, file_id, runnable)?; |
846 | if snap.config.lens.run { | 822 | if snap.config.lens.run { |
847 | let lens = CodeLens { | 823 | let lens = CodeLens { |
848 | range, | 824 | range, |
849 | command: Some(Command { | 825 | command: Some(run_single_command(&r, action.run_title)), |
850 | title: run_title.to_string(), | ||
851 | command: "rust-analyzer.runSingle".into(), | ||
852 | arguments: Some(vec![to_value(&r).unwrap()]), | ||
853 | }), | ||
854 | data: None, | 826 | data: None, |
855 | }; | 827 | }; |
856 | lenses.push(lens); | 828 | lenses.push(lens); |
857 | } | 829 | } |
858 | 830 | ||
859 | if debugee && snap.config.lens.debug { | 831 | if action.debugee && snap.config.lens.debug { |
860 | let debug_lens = CodeLens { | 832 | let debug_lens = CodeLens { |
861 | range, | 833 | range, |
862 | command: Some(Command { | 834 | command: Some(debug_single_command(r)), |
863 | title: "Debug".into(), | ||
864 | command: "rust-analyzer.debugSingle".into(), | ||
865 | arguments: Some(vec![to_value(r).unwrap()]), | ||
866 | }), | ||
867 | data: None, | 835 | data: None, |
868 | }; | 836 | }; |
869 | lenses.push(debug_lens); | 837 | lenses.push(debug_lens); |
@@ -1169,6 +1137,22 @@ fn show_references_command( | |||
1169 | } | 1137 | } |
1170 | } | 1138 | } |
1171 | 1139 | ||
1140 | fn run_single_command(runnable: &lsp_ext::Runnable, title: &str) -> Command { | ||
1141 | Command { | ||
1142 | title: title.to_string(), | ||
1143 | command: "rust-analyzer.runSingle".into(), | ||
1144 | arguments: Some(vec![to_value(runnable).unwrap()]), | ||
1145 | } | ||
1146 | } | ||
1147 | |||
1148 | fn debug_single_command(runnable: lsp_ext::Runnable) -> Command { | ||
1149 | Command { | ||
1150 | title: "Debug".into(), | ||
1151 | command: "rust-analyzer.debugSingle".into(), | ||
1152 | arguments: Some(vec![to_value(runnable).unwrap()]), | ||
1153 | } | ||
1154 | } | ||
1155 | |||
1172 | fn to_command_link(command: Command, tooltip: String) -> lsp_ext::CommandLink { | 1156 | fn to_command_link(command: Command, tooltip: String) -> lsp_ext::CommandLink { |
1173 | lsp_ext::CommandLink { tooltip: Some(tooltip), command } | 1157 | lsp_ext::CommandLink { tooltip: Some(tooltip), command } |
1174 | } | 1158 | } |
@@ -1214,3 +1198,17 @@ fn prepare_hover_actions( | |||
1214 | }) | 1198 | }) |
1215 | .collect() | 1199 | .collect() |
1216 | } | 1200 | } |
1201 | |||
1202 | fn is_lib_target(runnable: &Runnable, cargo_spec: Option<&CargoTargetSpec>) -> bool { | ||
1203 | // Do not suggest binary run on other target than binary | ||
1204 | if let RunnableKind::Bin = runnable.kind { | ||
1205 | if let Some(spec) = cargo_spec { | ||
1206 | match spec.target_kind { | ||
1207 | TargetKind::Bin => return true, | ||
1208 | _ => () | ||
1209 | } | ||
1210 | } | ||
1211 | } | ||
1212 | |||
1213 | false | ||
1214 | } \ No newline at end of file | ||