diff options
author | Aleksey Kladov <[email protected]> | 2019-01-05 14:22:41 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-05 14:24:17 +0000 |
commit | 3ad0037f907778d20ce6cfd9bf676a467b5734ad (patch) | |
tree | dd5b7a2f8e134c0452f88f8543cc16528cc1dc9e /crates/ra_lsp_server/src | |
parent | 2560a9e8076d0b83f606af3029ea1a0c7bc48514 (diff) |
move hover implementation to ra_analysis
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 50 |
1 files changed, 9 insertions, 41 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 2fc4d3649..ffca3f51c 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 | }; |
12 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity, NavigationTarget}; | 12 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity}; |
13 | use ra_syntax::{TextUnit, text_utils::intersect}; | 13 | use ra_syntax::{TextUnit, text_utils::intersect}; |
14 | use ra_text_edit::text_utils::contains_offset_nonstrict; | 14 | use ra_text_edit::text_utils::contains_offset_nonstrict; |
15 | use rustc_hash::FxHashMap; | 15 | use rustc_hash::FxHashMap; |
@@ -509,36 +509,18 @@ pub fn handle_hover( | |||
509 | world: ServerWorld, | 509 | world: ServerWorld, |
510 | params: req::TextDocumentPositionParams, | 510 | params: req::TextDocumentPositionParams, |
511 | ) -> Result<Option<Hover>> { | 511 | ) -> Result<Option<Hover>> { |
512 | // TODO: Cut down on number of allocations | ||
513 | let position = params.try_conv_with(&world)?; | 512 | let position = params.try_conv_with(&world)?; |
514 | let line_index = world.analysis().file_line_index(position.file_id); | 513 | let info = match world.analysis().hover(position)? { |
515 | let rr = match world.analysis().approximately_resolve_symbol(position)? { | ||
516 | None => return Ok(None), | 514 | None => return Ok(None), |
517 | Some(it) => it, | 515 | Some(info) => info, |
518 | }; | 516 | }; |
519 | let mut result = Vec::new(); | 517 | let line_index = world.analysis.file_line_index(position.file_id); |
520 | let file_id = params.text_document.try_conv_with(&world)?; | 518 | let range = info.range.conv_with(&line_index); |
521 | let file_range = FileRange { | 519 | let res = Hover { |
522 | file_id, | 520 | contents: HoverContents::Scalar(MarkedString::String(info.info)), |
523 | range: rr.reference_range, | 521 | range: Some(range), |
524 | }; | 522 | }; |
525 | if let Some(type_name) = get_type(&world, file_range) { | 523 | Ok(Some(res)) |
526 | result.push(type_name); | ||
527 | } | ||
528 | for nav in rr.resolves_to { | ||
529 | if let Some(docs) = get_doc_text(&world, nav) { | ||
530 | result.push(docs); | ||
531 | } | ||
532 | } | ||
533 | |||
534 | let range = rr.reference_range.conv_with(&line_index); | ||
535 | if result.len() > 0 { | ||
536 | return Ok(Some(Hover { | ||
537 | contents: HoverContents::Scalar(MarkedString::String(result.join("\n\n---\n"))), | ||
538 | range: Some(range), | ||
539 | })); | ||
540 | } | ||
541 | Ok(None) | ||
542 | } | 524 | } |
543 | 525 | ||
544 | /// Test doc comment | 526 | /// Test doc comment |
@@ -762,17 +744,3 @@ fn to_diagnostic_severity(severity: Severity) -> DiagnosticSeverity { | |||
762 | WeakWarning => DiagnosticSeverity::Hint, | 744 | WeakWarning => DiagnosticSeverity::Hint, |
763 | } | 745 | } |
764 | } | 746 | } |
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 | } | ||