From 3ad0037f907778d20ce6cfd9bf676a467b5734ad Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 5 Jan 2019 17:22:41 +0300 Subject: move hover implementation to ra_analysis --- crates/ra_lsp_server/src/main_loop/handlers.rs | 50 +++++--------------------- 1 file changed, 9 insertions(+), 41 deletions(-) (limited to 'crates/ra_lsp_server/src') 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::{ Range, WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents, DocumentFormattingParams, DocumentHighlight, }; -use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity, NavigationTarget}; +use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity}; use ra_syntax::{TextUnit, text_utils::intersect}; use ra_text_edit::text_utils::contains_offset_nonstrict; use rustc_hash::FxHashMap; @@ -509,36 +509,18 @@ pub fn handle_hover( world: ServerWorld, params: req::TextDocumentPositionParams, ) -> Result> { - // TODO: Cut down on number of allocations let position = params.try_conv_with(&world)?; - let line_index = world.analysis().file_line_index(position.file_id); - let rr = match world.analysis().approximately_resolve_symbol(position)? { + let info = match world.analysis().hover(position)? { None => return Ok(None), - Some(it) => it, + Some(info) => info, }; - let mut result = Vec::new(); - let file_id = params.text_document.try_conv_with(&world)?; - let file_range = FileRange { - file_id, - range: rr.reference_range, + let line_index = world.analysis.file_line_index(position.file_id); + let range = info.range.conv_with(&line_index); + let res = Hover { + contents: HoverContents::Scalar(MarkedString::String(info.info)), + range: Some(range), }; - if let Some(type_name) = get_type(&world, file_range) { - result.push(type_name); - } - for nav in rr.resolves_to { - if let Some(docs) = get_doc_text(&world, nav) { - result.push(docs); - } - } - - let range = rr.reference_range.conv_with(&line_index); - if result.len() > 0 { - return Ok(Some(Hover { - contents: HoverContents::Scalar(MarkedString::String(result.join("\n\n---\n"))), - range: Some(range), - })); - } - Ok(None) + Ok(Some(res)) } /// Test doc comment @@ -762,17 +744,3 @@ fn to_diagnostic_severity(severity: Severity) -> DiagnosticSeverity { WeakWarning => DiagnosticSeverity::Hint, } } - -fn get_type(world: &ServerWorld, file_range: FileRange) -> Option { - match world.analysis().type_of(file_range) { - Ok(result) => result, - _ => None, - } -} - -fn get_doc_text(world: &ServerWorld, nav: NavigationTarget) -> Option { - match world.analysis().doc_text_for(nav) { - Ok(result) => result, - _ => None, - } -} -- cgit v1.2.3