@@ -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 ;
@@ -514,29 +514,26 @@ pub fn handle_hover(
514
514
Some ( it) => it,
515
515
} ;
516
516
let mut result = Vec :: new ( ) ;
517
+ let file_id = params. text_document . try_conv_with ( & world) ?;
518
+ let file_range = FileRange {
519
+ file_id,
520
+ range : rr. reference_range ,
521
+ } ;
522
+ if let Some ( type_name) = get_type ( & world, file_range) {
523
+ result. push ( type_name) ;
524
+ }
517
525
for nav in rr. resolves_to {
518
- if let Some ( docs) = world . analysis ( ) . doc_text_for ( nav) ? {
526
+ if let Some ( docs) = get_doc_text ( & world , nav) {
519
527
result. push ( docs) ;
520
528
}
521
529
}
530
+
522
531
let range = rr. reference_range . conv_with ( & line_index) ;
523
532
if result. len ( ) > 0 {
524
533
return Ok ( Some ( Hover {
525
534
contents : HoverContents :: Scalar ( MarkedString :: String ( result. join ( "\n \n ---\n " ) ) ) ,
526
535
range : Some ( range) ,
527
536
} ) ) ;
528
- } else {
529
- let file_id = params. text_document . try_conv_with ( & world) ?;
530
- let file_range = FileRange {
531
- file_id,
532
- range : rr. reference_range ,
533
- } ;
534
- if let Some ( type_name) = world. analysis ( ) . type_of ( file_range) ? {
535
- return Ok ( Some ( Hover {
536
- contents : HoverContents :: Scalar ( MarkedString :: String ( type_name) ) ,
537
- range : Some ( range) ,
538
- } ) ) ;
539
- }
540
537
}
541
538
Ok ( None )
542
539
}
@@ -762,3 +759,17 @@ fn to_diagnostic_severity(severity: Severity) -> DiagnosticSeverity {
762
759
WeakWarning => DiagnosticSeverity :: Hint ,
763
760
}
764
761
}
762
+
763
+ fn get_type ( world : & ServerWorld , file_range : FileRange ) -> Option < String > {
764
+ match world. analysis ( ) . type_of ( file_range) {
765
+ Ok ( result) => result,
766
+ _ => None ,
767
+ }
768
+ }
769
+
770
+ fn get_doc_text ( world : & ServerWorld , nav : NavigationTarget ) -> Option < String > {
771
+ match world. analysis ( ) . doc_text_for ( nav) {
772
+ Ok ( result) => result,
773
+ _ => None ,
774
+ }
775
+ }
0 commit comments