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
3
4
use hir:: {
4
5
Adt , AsAssocItem , AssocItemContainer , FieldSource , HasSource , HirDisplay , ModuleDef ,
@@ -24,35 +25,20 @@ use itertools::Itertools;
24
25
use std:: iter:: once;
25
26
26
27
/// Contains the results when hovering over an item
27
- #[ derive( Debug , Clone ) ]
28
+ #[ derive( Debug , Default ) ]
28
29
pub struct HoverResult {
29
30
results : Vec < String > ,
30
- exact : bool ,
31
- }
32
-
33
- impl Default for HoverResult {
34
- fn default ( ) -> Self {
35
- HoverResult :: new ( )
36
- }
37
31
}
38
32
39
33
impl HoverResult {
40
34
pub fn new ( ) -> HoverResult {
41
- HoverResult {
42
- results : Vec :: new ( ) ,
43
- // We assume exact by default
44
- exact : true ,
45
- }
35
+ Self :: default ( )
46
36
}
47
37
48
38
pub fn extend ( & mut self , item : Option < String > ) {
49
39
self . results . extend ( item) ;
50
40
}
51
41
52
- pub fn is_exact ( & self ) -> bool {
53
- self . exact
54
- }
55
-
56
42
pub fn is_empty ( & self ) -> bool {
57
43
self . results . is_empty ( )
58
44
}
@@ -72,20 +58,7 @@ impl HoverResult {
72
58
/// Returns the results converted into markup
73
59
/// for displaying in a UI
74
60
pub fn to_markup ( & self ) -> String {
75
- let mut markup = if !self . exact {
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 ( " \n These 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
61
+ self . results . join ( "\n \n ---\n " )
89
62
}
90
63
}
91
64
@@ -595,7 +568,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
595
568
) ;
596
569
let hover = analysis. hover ( position) . unwrap ( ) . unwrap ( ) ;
597
570
assert_eq ! ( trim_markup_opt( hover. info. first( ) ) , Some ( "wrapper::Thing\n fn new() -> Thing" ) ) ;
598
- assert_eq ! ( hover. info. is_exact( ) , true ) ;
599
571
}
600
572
601
573
#[ test]
@@ -618,7 +590,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
618
590
) ;
619
591
let hover = analysis. hover ( position) . unwrap ( ) . unwrap ( ) ;
620
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
595
#[ test]
@@ -635,7 +606,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
635
606
) ;
636
607
let hover = analysis. hover ( position) . unwrap ( ) . unwrap ( ) ;
637
608
assert_eq ! ( trim_markup_opt( hover. info. first( ) ) , Some ( "Thing" ) ) ;
638
- assert_eq ! ( hover. info. is_exact( ) , true ) ;
639
609
640
610
/* FIXME: revive these tests
641
611
let (analysis, position) = single_file_with_position(
@@ -651,7 +621,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
651
621
652
622
let hover = analysis.hover(position).unwrap().unwrap();
653
623
assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
654
- assert_eq!(hover.info.is_exact(), true);
655
624
656
625
let (analysis, position) = single_file_with_position(
657
626
"
@@ -665,7 +634,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
665
634
);
666
635
let hover = analysis.hover(position).unwrap().unwrap();
667
636
assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
668
- assert_eq!(hover.info.is_exact(), true);
669
637
670
638
let (analysis, position) = single_file_with_position(
671
639
"
@@ -678,7 +646,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
678
646
);
679
647
let hover = analysis.hover(position).unwrap().unwrap();
680
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
664
let hover = analysis. hover ( position) . unwrap ( ) . unwrap ( ) ;
698
665
assert_eq ! ( trim_markup_opt( hover. info. first( ) ) , Some ( "i32" ) ) ;
699
- assert_eq ! ( hover. info. is_exact( ) , true ) ;
700
666
}
701
667
702
668
#[ test]
@@ -714,7 +680,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
714
680
) ;
715
681
let hover = analysis. hover ( position) . unwrap ( ) . unwrap ( ) ;
716
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
685
#[ test]
@@ -726,7 +691,6 @@ fn func(foo: i32) { if true { <|>foo; }; }
726
691
) ;
727
692
let hover = analysis. hover ( position) . unwrap ( ) . unwrap ( ) ;
728
693
assert_eq ! ( trim_markup_opt( hover. info. first( ) ) , Some ( "i32" ) ) ;
729
- assert_eq ! ( hover. info. is_exact( ) , true ) ;
730
694
}
731
695
732
696
#[ test]
0 commit comments