diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-13 13:50:35 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-13 13:50:35 +0000 |
commit | 7accf6bc37c059a83a58c82f463f02a02ed2226f (patch) | |
tree | 979c8ebe39bde9c989cb1a09f06cea4cf7cb04ac /crates/rust-analyzer/src/handlers.rs | |
parent | 9674490b45a931399a9a05cd3a4c7e8fae9ec2a8 (diff) | |
parent | 49cdb2452a225dec3834e69fb011c3d7e68084f7 (diff) |
Merge #7799
7799: Related tests r=matklad a=vsrs
![tests](https://user-images.githubusercontent.com/62505555/109397453-a9013680-7947-11eb-8b11-ac03079f7645.gif)
This adds an ability to look for tests for the item under the cursor: function, constant, data type, etc
The LSP part is bound to change. But the feature itself already works and I'm looking for a feedback :)
Co-authored-by: vsrs <[email protected]>
Diffstat (limited to 'crates/rust-analyzer/src/handlers.rs')
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 6cc433cb8..706a39dab 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -555,7 +555,7 @@ pub(crate) fn handle_runnables( | |||
555 | if should_skip_target(&runnable, cargo_spec.as_ref()) { | 555 | if should_skip_target(&runnable, cargo_spec.as_ref()) { |
556 | continue; | 556 | continue; |
557 | } | 557 | } |
558 | let mut runnable = to_proto::runnable(&snap, file_id, runnable)?; | 558 | let mut runnable = to_proto::runnable(&snap, runnable)?; |
559 | if expect_test { | 559 | if expect_test { |
560 | runnable.label = format!("{} + expect", runnable.label); | 560 | runnable.label = format!("{} + expect", runnable.label); |
561 | runnable.args.expect_test = Some(true); | 561 | runnable.args.expect_test = Some(true); |
@@ -607,6 +607,24 @@ pub(crate) fn handle_runnables( | |||
607 | Ok(res) | 607 | Ok(res) |
608 | } | 608 | } |
609 | 609 | ||
610 | pub(crate) fn handle_related_tests( | ||
611 | snap: GlobalStateSnapshot, | ||
612 | params: lsp_types::TextDocumentPositionParams, | ||
613 | ) -> Result<Vec<lsp_ext::TestInfo>> { | ||
614 | let _p = profile::span("handle_related_tests"); | ||
615 | let position = from_proto::file_position(&snap, params)?; | ||
616 | |||
617 | let tests = snap.analysis.related_tests(position, None)?; | ||
618 | let mut res = Vec::new(); | ||
619 | for it in tests { | ||
620 | if let Ok(runnable) = to_proto::runnable(&snap, it) { | ||
621 | res.push(lsp_ext::TestInfo { runnable }) | ||
622 | } | ||
623 | } | ||
624 | |||
625 | Ok(res) | ||
626 | } | ||
627 | |||
610 | pub(crate) fn handle_completion( | 628 | pub(crate) fn handle_completion( |
611 | snap: GlobalStateSnapshot, | 629 | snap: GlobalStateSnapshot, |
612 | params: lsp_types::CompletionParams, | 630 | params: lsp_types::CompletionParams, |
@@ -772,7 +790,7 @@ pub(crate) fn handle_hover( | |||
772 | contents: HoverContents::Markup(to_proto::markup_content(info.info.markup)), | 790 | contents: HoverContents::Markup(to_proto::markup_content(info.info.markup)), |
773 | range: Some(range), | 791 | range: Some(range), |
774 | }, | 792 | }, |
775 | actions: prepare_hover_actions(&snap, position.file_id, &info.info.actions), | 793 | actions: prepare_hover_actions(&snap, &info.info.actions), |
776 | }; | 794 | }; |
777 | 795 | ||
778 | Ok(Some(hover)) | 796 | Ok(Some(hover)) |
@@ -1440,17 +1458,16 @@ fn show_impl_command_link( | |||
1440 | 1458 | ||
1441 | fn runnable_action_links( | 1459 | fn runnable_action_links( |
1442 | snap: &GlobalStateSnapshot, | 1460 | snap: &GlobalStateSnapshot, |
1443 | file_id: FileId, | ||
1444 | runnable: Runnable, | 1461 | runnable: Runnable, |
1445 | ) -> Option<lsp_ext::CommandLinkGroup> { | 1462 | ) -> Option<lsp_ext::CommandLinkGroup> { |
1446 | let cargo_spec = CargoTargetSpec::for_file(&snap, file_id).ok()?; | 1463 | let cargo_spec = CargoTargetSpec::for_file(&snap, runnable.nav.file_id).ok()?; |
1447 | let hover_config = snap.config.hover(); | 1464 | let hover_config = snap.config.hover(); |
1448 | if !hover_config.runnable() || should_skip_target(&runnable, cargo_spec.as_ref()) { | 1465 | if !hover_config.runnable() || should_skip_target(&runnable, cargo_spec.as_ref()) { |
1449 | return None; | 1466 | return None; |
1450 | } | 1467 | } |
1451 | 1468 | ||
1452 | let action: &'static _ = runnable.action(); | 1469 | let action: &'static _ = runnable.action(); |
1453 | to_proto::runnable(snap, file_id, runnable).ok().map(|r| { | 1470 | to_proto::runnable(snap, runnable).ok().map(|r| { |
1454 | let mut group = lsp_ext::CommandLinkGroup::default(); | 1471 | let mut group = lsp_ext::CommandLinkGroup::default(); |
1455 | 1472 | ||
1456 | if hover_config.run { | 1473 | if hover_config.run { |
@@ -1489,7 +1506,6 @@ fn goto_type_action_links( | |||
1489 | 1506 | ||
1490 | fn prepare_hover_actions( | 1507 | fn prepare_hover_actions( |
1491 | snap: &GlobalStateSnapshot, | 1508 | snap: &GlobalStateSnapshot, |
1492 | file_id: FileId, | ||
1493 | actions: &[HoverAction], | 1509 | actions: &[HoverAction], |
1494 | ) -> Vec<lsp_ext::CommandLinkGroup> { | 1510 | ) -> Vec<lsp_ext::CommandLinkGroup> { |
1495 | if snap.config.hover().none() || !snap.config.hover_actions() { | 1511 | if snap.config.hover().none() || !snap.config.hover_actions() { |
@@ -1500,7 +1516,7 @@ fn prepare_hover_actions( | |||
1500 | .iter() | 1516 | .iter() |
1501 | .filter_map(|it| match it { | 1517 | .filter_map(|it| match it { |
1502 | HoverAction::Implementation(position) => show_impl_command_link(snap, position), | 1518 | HoverAction::Implementation(position) => show_impl_command_link(snap, position), |
1503 | HoverAction::Runnable(r) => runnable_action_links(snap, file_id, r.clone()), | 1519 | HoverAction::Runnable(r) => runnable_action_links(snap, r.clone()), |
1504 | HoverAction::GoToType(targets) => goto_type_action_links(snap, targets), | 1520 | HoverAction::GoToType(targets) => goto_type_action_links(snap, targets), |
1505 | }) | 1521 | }) |
1506 | .collect() | 1522 | .collect() |