@@ -9,7 +9,7 @@ use languageserver_types::{
9
9
Range , WorkspaceEdit , ParameterInformation , ParameterLabel , SignatureInformation , Hover ,
10
10
HoverContents , DocumentFormattingParams , DocumentHighlight ,
11
11
} ;
12
- use ra_analysis:: { FileId , FoldKind , Query , RunnableKind , FileRange , FilePosition , Severity } ;
12
+ use ra_analysis:: { FileId , FoldKind , Query , RunnableKind , FileRange , FilePosition , Severity , NavigationTarget } ;
13
13
use ra_syntax:: { TextUnit , text_utils:: intersect} ;
14
14
use ra_text_edit:: text_utils:: contains_offset_nonstrict;
15
15
use rustc_hash:: FxHashMap ;
@@ -517,11 +517,20 @@ pub fn handle_hover(
517
517
Some ( it) => it,
518
518
} ;
519
519
let mut result = Vec :: new ( ) ;
520
+ let file_id = params. text_document . try_conv_with ( & world) ?;
521
+ let file_range = FileRange {
522
+ file_id,
523
+ range : rr. reference_range ,
524
+ } ;
525
+ if let Some ( type_name) = get_type ( & world, file_range) {
526
+ result. push ( type_name) ;
527
+ }
520
528
for nav in rr. resolves_to {
521
- if let Some ( docs) = world . analysis ( ) . doc_text_for ( nav) ? {
529
+ if let Some ( docs) = get_doc_text ( & world , nav) {
522
530
result. push ( docs) ;
523
531
}
524
532
}
533
+
525
534
let range = rr. reference_range . conv_with ( & line_index) ;
526
535
if result. len ( ) > 0 {
527
536
return Ok ( Some ( Hover {
@@ -753,3 +762,17 @@ fn to_diagnostic_severity(severity: Severity) -> DiagnosticSeverity {
753
762
WeakWarning => DiagnosticSeverity :: Hint ,
754
763
}
755
764
}
765
+
766
+ fn get_type ( world : & ServerWorld , file_range : FileRange ) -> Option < String > {
767
+ match world. analysis ( ) . type_of ( file_range) {
768
+ Ok ( result) => result,
769
+ _ => None ,
770
+ }
771
+ }
772
+
773
+ fn get_doc_text ( world : & ServerWorld , nav : NavigationTarget ) -> Option < String > {
774
+ match world. analysis ( ) . doc_text_for ( nav) {
775
+ Ok ( result) => result,
776
+ _ => None ,
777
+ }
778
+ }
0 commit comments