aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs39
1 files changed, 25 insertions, 14 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 705d1360f..06ae9a64a 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;
@@ -514,29 +514,26 @@ pub fn handle_hover(
514 Some(it) => it, 514 Some(it) => it,
515 }; 515 };
516 let mut result = Vec::new(); 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 for nav in rr.resolves_to { 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 result.push(docs); 527 result.push(docs);
520 } 528 }
521 } 529 }
530
522 let range = rr.reference_range.conv_with(&line_index); 531 let range = rr.reference_range.conv_with(&line_index);
523 if result.len() > 0 { 532 if result.len() > 0 {
524 return Ok(Some(Hover { 533 return Ok(Some(Hover {
525 contents: HoverContents::Scalar(MarkedString::String(result.join("\n\n---\n"))), 534 contents: HoverContents::Scalar(MarkedString::String(result.join("\n\n---\n"))),
526 range: Some(range), 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 Ok(None) 538 Ok(None)
542} 539}
@@ -762,3 +759,17 @@ fn to_diagnostic_severity(severity: Severity) -> DiagnosticSeverity {
762 WeakWarning => DiagnosticSeverity::Hint, 759 WeakWarning => DiagnosticSeverity::Hint,
763 } 760 }
764} 761}
762
763fn 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
770fn 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}