From 6ee7788513960ddf11254aca50da012b58df4583 Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Thu, 3 Jan 2019 21:15:23 +0900 Subject: Return type name when doc_text_for returns nothing --- crates/ra_lsp_server/src/main_loop/handlers.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (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 b5792f3b8..705d1360f 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -525,6 +525,18 @@ pub fn handle_hover( contents: HoverContents::Scalar(MarkedString::String(result.join("\n\n---\n"))), range: Some(range), })); + } else { + let file_id = params.text_document.try_conv_with(&world)?; + let file_range = FileRange { + file_id, + range: rr.reference_range, + }; + if let Some(type_name) = world.analysis().type_of(file_range)? { + return Ok(Some(Hover { + contents: HoverContents::Scalar(MarkedString::String(type_name)), + range: Some(range), + })); + } } Ok(None) } -- cgit v1.2.3 From 341eb4ae87de8cebc3bfc564970a4f1430af4dc1 Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Fri, 4 Jan 2019 19:06:46 +0900 Subject: Use both type_of and doc_text_for --- crates/ra_lsp_server/src/main_loop/handlers.rs | 39 +++++++++++++++++--------- 1 file changed, 25 insertions(+), 14 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 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::{ Range, WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents, DocumentFormattingParams, DocumentHighlight, }; -use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity}; +use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity, NavigationTarget}; use ra_syntax::{TextUnit, text_utils::intersect}; use ra_text_edit::text_utils::contains_offset_nonstrict; use rustc_hash::FxHashMap; @@ -514,29 +514,26 @@ pub fn handle_hover( Some(it) => it, }; 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, + }; + if let Some(type_name) = get_type(&world, file_range) { + result.push(type_name); + } for nav in rr.resolves_to { - if let Some(docs) = world.analysis().doc_text_for(nav)? { + 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), })); - } else { - let file_id = params.text_document.try_conv_with(&world)?; - let file_range = FileRange { - file_id, - range: rr.reference_range, - }; - if let Some(type_name) = world.analysis().type_of(file_range)? { - return Ok(Some(Hover { - contents: HoverContents::Scalar(MarkedString::String(type_name)), - range: Some(range), - })); - } } Ok(None) } @@ -762,3 +759,17 @@ 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