aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
authorveetaha <[email protected]>2020-03-15 23:30:50 +0000
committerveetaha <[email protected]>2020-03-15 23:30:50 +0000
commit4fd07a02a2bcbb8ff97df6d24112ee6204be362a (patch)
tree6ec88b175feadaa8694772d360939ab09e80057f /crates/ra_ide/src
parentbf0c3ec67e0f2bc232924923ef3bd55aa3bd0cbd (diff)
ra_ide: remove dead code in HoverResult
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/hover.rs46
1 files changed, 5 insertions, 41 deletions
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index 0bbba4855..475ceadd1 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -1,4 +1,5 @@
1//! FIXME: write short doc here 1//! Logic for computing info that is displayed when the user hovers over any
2//! source code items (e.g. function call, struct field, variable symbol...)
2 3
3use hir::{ 4use hir::{
4 Adt, AsAssocItem, AssocItemContainer, FieldSource, HasSource, HirDisplay, ModuleDef, 5 Adt, AsAssocItem, AssocItemContainer, FieldSource, HasSource, HirDisplay, ModuleDef,
@@ -24,35 +25,20 @@ use itertools::Itertools;
24use std::iter::once; 25use std::iter::once;
25 26
26/// Contains the results when hovering over an item 27/// Contains the results when hovering over an item
27#[derive(Debug, Clone)] 28#[derive(Debug, Default)]
28pub struct HoverResult { 29pub struct HoverResult {
29 results: Vec<String>, 30 results: Vec<String>,
30 exact: bool,
31}
32
33impl Default for HoverResult {
34 fn default() -> Self {
35 HoverResult::new()
36 }
37} 31}
38 32
39impl HoverResult { 33impl HoverResult {
40 pub fn new() -> HoverResult { 34 pub fn new() -> HoverResult {
41 HoverResult { 35 Self::default()
42 results: Vec::new(),
43 // We assume exact by default
44 exact: true,
45 }
46 } 36 }
47 37
48 pub fn extend(&mut self, item: Option<String>) { 38 pub fn extend(&mut self, item: Option<String>) {
49 self.results.extend(item); 39 self.results.extend(item);
50 } 40 }
51 41
52 pub fn is_exact(&self) -> bool {
53 self.exact
54 }
55
56 pub fn is_empty(&self) -> bool { 42 pub fn is_empty(&self) -> bool {
57 self.results.is_empty() 43 self.results.is_empty()
58 } 44 }
@@ -72,20 +58,7 @@ impl HoverResult {
72 /// Returns the results converted into markup 58 /// Returns the results converted into markup
73 /// for displaying in a UI 59 /// for displaying in a UI
74 pub fn to_markup(&self) -> String { 60 pub fn to_markup(&self) -> String {
75 let mut markup = if !self.exact { 61 self.results.join("\n\n---\n")
76 let mut msg = String::from("Failed to exactly resolve the symbol. This is probably because rust_analyzer does not yet support traits.");
77 if !self.results.is_empty() {
78 msg.push_str(" \nThese items were found instead:");
79 }
80 msg.push_str("\n\n---\n");
81 msg
82 } else {
83 String::new()
84 };
85
86 markup.push_str(&self.results.join("\n\n---\n"));
87
88 markup
89 } 62 }
90} 63}
91 64
@@ -595,7 +568,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
595 ); 568 );
596 let hover = analysis.hover(position).unwrap().unwrap(); 569 let hover = analysis.hover(position).unwrap().unwrap();
597 assert_eq!(trim_markup_opt(hover.info.first()), Some("wrapper::Thing\nfn new() -> Thing")); 570 assert_eq!(trim_markup_opt(hover.info.first()), Some("wrapper::Thing\nfn new() -> Thing"));
598 assert_eq!(hover.info.is_exact(), true);
599 } 571 }
600 572
601 #[test] 573 #[test]
@@ -618,7 +590,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
618 ); 590 );
619 let hover = analysis.hover(position).unwrap().unwrap(); 591 let hover = analysis.hover(position).unwrap().unwrap();
620 assert_eq!(trim_markup_opt(hover.info.first()), Some("const C: u32")); 592 assert_eq!(trim_markup_opt(hover.info.first()), Some("const C: u32"));
621 assert_eq!(hover.info.is_exact(), true);
622 } 593 }
623 594
624 #[test] 595 #[test]
@@ -635,7 +606,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
635 ); 606 );
636 let hover = analysis.hover(position).unwrap().unwrap(); 607 let hover = analysis.hover(position).unwrap().unwrap();
637 assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing")); 608 assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
638 assert_eq!(hover.info.is_exact(), true);
639 609
640 /* FIXME: revive these tests 610 /* FIXME: revive these tests
641 let (analysis, position) = single_file_with_position( 611 let (analysis, position) = single_file_with_position(
@@ -651,7 +621,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
651 621
652 let hover = analysis.hover(position).unwrap().unwrap(); 622 let hover = analysis.hover(position).unwrap().unwrap();
653 assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing")); 623 assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
654 assert_eq!(hover.info.is_exact(), true);
655 624
656 let (analysis, position) = single_file_with_position( 625 let (analysis, position) = single_file_with_position(
657 " 626 "
@@ -665,7 +634,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
665 ); 634 );
666 let hover = analysis.hover(position).unwrap().unwrap(); 635 let hover = analysis.hover(position).unwrap().unwrap();
667 assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); 636 assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
668 assert_eq!(hover.info.is_exact(), true);
669 637
670 let (analysis, position) = single_file_with_position( 638 let (analysis, position) = single_file_with_position(
671 " 639 "
@@ -678,7 +646,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
678 ); 646 );
679 let hover = analysis.hover(position).unwrap().unwrap(); 647 let hover = analysis.hover(position).unwrap().unwrap();
680 assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing")); 648 assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
681 assert_eq!(hover.info.is_exact(), true);
682 */ 649 */
683 } 650 }
684 651
@@ -696,7 +663,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
696 ); 663 );
697 let hover = analysis.hover(position).unwrap().unwrap(); 664 let hover = analysis.hover(position).unwrap().unwrap();
698 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); 665 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
699 assert_eq!(hover.info.is_exact(), true);
700 } 666 }
701 667
702 #[test] 668 #[test]
@@ -714,7 +680,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
714 ); 680 );
715 let hover = analysis.hover(position).unwrap().unwrap(); 681 let hover = analysis.hover(position).unwrap().unwrap();
716 assert_eq!(trim_markup_opt(hover.info.first()), Some("macro_rules! foo")); 682 assert_eq!(trim_markup_opt(hover.info.first()), Some("macro_rules! foo"));
717 assert_eq!(hover.info.is_exact(), true);
718 } 683 }
719 684
720 #[test] 685 #[test]
@@ -726,7 +691,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
726 ); 691 );
727 let hover = analysis.hover(position).unwrap().unwrap(); 692 let hover = analysis.hover(position).unwrap().unwrap();
728 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); 693 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
729 assert_eq!(hover.info.is_exact(), true);
730 } 694 }
731 695
732 #[test] 696 #[test]