aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs27
1 files changed, 25 insertions, 2 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 4e895a9a9..2fc4d3649 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -9,7 +9,7 @@ use languageserver_types::{
9 Range, WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, 9 Range, WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover,
10 HoverContents, DocumentFormattingParams, DocumentHighlight, 10 HoverContents, DocumentFormattingParams, DocumentHighlight,
11}; 11};
12use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity}; 12use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity, NavigationTarget};
13use ra_syntax::{TextUnit, text_utils::intersect}; 13use ra_syntax::{TextUnit, text_utils::intersect};
14use ra_text_edit::text_utils::contains_offset_nonstrict; 14use ra_text_edit::text_utils::contains_offset_nonstrict;
15use rustc_hash::FxHashMap; 15use rustc_hash::FxHashMap;
@@ -517,11 +517,20 @@ pub fn handle_hover(
517 Some(it) => it, 517 Some(it) => it,
518 }; 518 };
519 let mut result = Vec::new(); 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 for nav in rr.resolves_to { 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 result.push(docs); 530 result.push(docs);
523 } 531 }
524 } 532 }
533
525 let range = rr.reference_range.conv_with(&line_index); 534 let range = rr.reference_range.conv_with(&line_index);
526 if result.len() > 0 { 535 if result.len() > 0 {
527 return Ok(Some(Hover { 536 return Ok(Some(Hover {
@@ -753,3 +762,17 @@ fn to_diagnostic_severity(severity: Severity) -> DiagnosticSeverity {
753 WeakWarning => DiagnosticSeverity::Hint, 762 WeakWarning => DiagnosticSeverity::Hint,
754 } 763 }
755} 764}
765
766fn 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
773fn 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}