diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/main_loop/handlers.rs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index cae447eea..eaa43f2bd 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs | |||
@@ -404,7 +404,7 @@ pub fn handle_runnables( | |||
404 | continue; | 404 | continue; |
405 | } | 405 | } |
406 | } | 406 | } |
407 | if is_lib_target(&runnable, cargo_spec.as_ref()) { | 407 | if should_skip_target(&runnable, cargo_spec.as_ref()) { |
408 | continue; | 408 | continue; |
409 | } | 409 | } |
410 | 410 | ||
@@ -812,7 +812,7 @@ pub fn handle_code_lens( | |||
812 | if snap.config.lens.runnable() { | 812 | if snap.config.lens.runnable() { |
813 | // Gather runnables | 813 | // Gather runnables |
814 | for runnable in snap.analysis().runnables(file_id)? { | 814 | for runnable in snap.analysis().runnables(file_id)? { |
815 | if is_lib_target(&runnable, cargo_spec.as_ref()) { | 815 | if should_skip_target(&runnable, cargo_spec.as_ref()) { |
816 | continue; | 816 | continue; |
817 | } | 817 | } |
818 | 818 | ||
@@ -1185,6 +1185,11 @@ fn to_runnable_action( | |||
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()?; | ||
1189 | if should_skip_target(runnable, cargo_spec.as_ref()) { | ||
1190 | return None; | ||
1191 | } | ||
1192 | |||
1188 | to_proto::runnable(snap, file_id, runnable).ok().map(|r| { | 1193 | to_proto::runnable(snap, file_id, runnable).ok().map(|r| { |
1189 | let mut group = lsp_ext::CommandLinkGroup::default(); | 1194 | let mut group = lsp_ext::CommandLinkGroup::default(); |
1190 | 1195 | ||
@@ -1222,16 +1227,18 @@ fn prepare_hover_actions( | |||
1222 | .collect() | 1227 | .collect() |
1223 | } | 1228 | } |
1224 | 1229 | ||
1225 | fn is_lib_target(runnable: &Runnable, cargo_spec: Option<&CargoTargetSpec>) -> bool { | 1230 | fn should_skip_target(runnable: &Runnable, cargo_spec: Option<&CargoTargetSpec>) -> bool { |
1226 | // Do not suggest binary run on other target than binary | 1231 | match runnable.kind { |
1227 | if let RunnableKind::Bin = runnable.kind { | 1232 | RunnableKind::Bin => { |
1228 | if let Some(spec) = cargo_spec { | 1233 | // Do not suggest binary run on other target than binary |
1229 | match spec.target_kind { | 1234 | match &cargo_spec { |
1230 | TargetKind::Bin => return true, | 1235 | Some(spec) => match spec.target_kind { |
1231 | _ => (), | 1236 | TargetKind::Bin => false, |
1237 | _ => true, | ||
1238 | }, | ||
1239 | None => true, | ||
1232 | } | 1240 | } |
1233 | } | 1241 | } |
1242 | _ => false, | ||
1234 | } | 1243 | } |
1235 | |||
1236 | false | ||
1237 | } | 1244 | } |