diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-07 18:30:13 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-07 18:30:13 +0100 |
commit | 97b9b364d65b00ce2246da7670a3823a0bccc1d3 (patch) | |
tree | b15f7768ac8df06c3eeeb039a1063d3e9065b673 | |
parent | aa112bf7146a41c56ee9ed36f2120d0ee9c33e4b (diff) | |
parent | c839d4f7a9e667b5aca30388c43fa8b1dbab14a7 (diff) |
Merge #4362
4362: do not show runnables for main function outside of a binary target r=matklad a=bnjjj
close #4356
Co-authored-by: Benjamin Coenen <[email protected]>
-rw-r--r-- | crates/rust-analyzer/src/main_loop/handlers.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index 15e8305f8..f4353af64 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs | |||
@@ -42,6 +42,7 @@ use crate::{ | |||
42 | world::WorldSnapshot, | 42 | world::WorldSnapshot, |
43 | LspError, Result, | 43 | LspError, Result, |
44 | }; | 44 | }; |
45 | use ra_project_model::TargetKind; | ||
45 | 46 | ||
46 | pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> { | 47 | pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> { |
47 | let _p = profile("handle_analyzer_status"); | 48 | let _p = profile("handle_analyzer_status"); |
@@ -384,16 +385,27 @@ pub fn handle_runnables( | |||
384 | let offset = params.position.map(|it| it.conv_with(&line_index)); | 385 | let offset = params.position.map(|it| it.conv_with(&line_index)); |
385 | let mut res = Vec::new(); | 386 | let mut res = Vec::new(); |
386 | let workspace_root = world.workspace_root_for(file_id); | 387 | let workspace_root = world.workspace_root_for(file_id); |
388 | let cargo_spec = CargoTargetSpec::for_file(&world, file_id)?; | ||
387 | for runnable in world.analysis().runnables(file_id)? { | 389 | for runnable in world.analysis().runnables(file_id)? { |
388 | if let Some(offset) = offset { | 390 | if let Some(offset) = offset { |
389 | if !runnable.range.contains_inclusive(offset) { | 391 | if !runnable.range.contains_inclusive(offset) { |
390 | continue; | 392 | continue; |
391 | } | 393 | } |
392 | } | 394 | } |
395 | // Do not suggest binary run on other target than binary | ||
396 | if let RunnableKind::Bin = runnable.kind { | ||
397 | if let Some(spec) = &cargo_spec { | ||
398 | match spec.target_kind { | ||
399 | TargetKind::Bin => {} | ||
400 | _ => continue, | ||
401 | } | ||
402 | } | ||
403 | } | ||
393 | res.push(to_lsp_runnable(&world, file_id, runnable)?); | 404 | res.push(to_lsp_runnable(&world, file_id, runnable)?); |
394 | } | 405 | } |
406 | |||
395 | // Add `cargo check` and `cargo test` for the whole package | 407 | // Add `cargo check` and `cargo test` for the whole package |
396 | match CargoTargetSpec::for_file(&world, file_id)? { | 408 | match cargo_spec { |
397 | Some(spec) => { | 409 | Some(spec) => { |
398 | for &cmd in ["check", "test"].iter() { | 410 | for &cmd in ["check", "test"].iter() { |
399 | res.push(req::Runnable { | 411 | res.push(req::Runnable { |
@@ -831,13 +843,23 @@ pub fn handle_code_lens( | |||
831 | 843 | ||
832 | let mut lenses: Vec<CodeLens> = Default::default(); | 844 | let mut lenses: Vec<CodeLens> = Default::default(); |
833 | 845 | ||
846 | let cargo_spec = CargoTargetSpec::for_file(&world, file_id)?; | ||
834 | // Gather runnables | 847 | // Gather runnables |
835 | for runnable in world.analysis().runnables(file_id)? { | 848 | for runnable in world.analysis().runnables(file_id)? { |
836 | let title = match &runnable.kind { | 849 | let title = match &runnable.kind { |
837 | RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => "▶️\u{fe0e}Run Test", | 850 | RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => "▶️\u{fe0e}Run Test", |
838 | RunnableKind::DocTest { .. } => "▶️\u{fe0e}Run Doctest", | 851 | RunnableKind::DocTest { .. } => "▶️\u{fe0e}Run Doctest", |
839 | RunnableKind::Bench { .. } => "Run Bench", | 852 | RunnableKind::Bench { .. } => "Run Bench", |
840 | RunnableKind::Bin => "Run", | 853 | RunnableKind::Bin => { |
854 | // Do not suggest binary run on other target than binary | ||
855 | match &cargo_spec { | ||
856 | Some(spec) => match spec.target_kind { | ||
857 | TargetKind::Bin => "Run", | ||
858 | _ => continue, | ||
859 | }, | ||
860 | None => continue, | ||
861 | } | ||
862 | } | ||
841 | } | 863 | } |
842 | .to_string(); | 864 | .to_string(); |
843 | let mut r = to_lsp_runnable(&world, file_id, runnable)?; | 865 | let mut r = to_lsp_runnable(&world, file_id, runnable)?; |