From 8ccd26adf396b49c7ba9e3abe0a92869b1a4c728 Mon Sep 17 00:00:00 2001 From: "Jeremy A. Kolb" Date: Mon, 5 Nov 2018 16:37:27 -0500 Subject: Show documentation for hover requests --- crates/ra_lsp_server/src/caps.rs | 2 +- crates/ra_lsp_server/src/main_loop/handlers.rs | 29 ++++++++++++++++++++++++-- crates/ra_lsp_server/src/main_loop/mod.rs | 1 + 3 files changed, 29 insertions(+), 3 deletions(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs index 0d02c8073..bcf857fce 100644 --- a/crates/ra_lsp_server/src/caps.rs +++ b/crates/ra_lsp_server/src/caps.rs @@ -16,7 +16,7 @@ pub fn server_capabilities() -> ServerCapabilities { save: None, }, )), - hover_provider: None, + hover_provider: Some(true), completion_provider: Some(CompletionOptions { resolve_provider: None, trigger_characters: None, diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 5314a333e..97ab53f91 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -4,9 +4,9 @@ use gen_lsp_server::ErrorCode; use languageserver_types::{ CodeActionResponse, Command, CompletionItem, CompletionItemKind, Diagnostic, DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind, - FoldingRangeParams, InsertTextFormat, Location, MarkupContent, MarkupKind, Position, + FoldingRangeParams, InsertTextFormat, Location, MarkupContent, MarkupKind, MarkedString, Position, PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, - WorkspaceEdit, ParameterInformation, SignatureInformation, + WorkspaceEdit, ParameterInformation, SignatureInformation, Hover, HoverContents, }; use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; use ra_syntax::text_utils::contains_offset_nonstrict; @@ -478,6 +478,31 @@ pub fn handle_signature_help( } } +pub fn handle_hover( + world: ServerWorld, + params: req::TextDocumentPositionParams, +) -> Result> { + let position = params.try_conv_with(&world)?; + let line_index = world.analysis().file_line_index(position.file_id); + + for (file_id, symbol) in world.analysis().approximately_resolve_symbol(position)? { + let range = symbol.node_range.conv_with(&line_index); + let name = symbol.name.to_string(); + let comment = world.analysis.doc_comment_for(file_id, symbol)?; + + if comment.is_some() { + let contents = HoverContents::Scalar(MarkedString::String(comment.unwrap())); + + return Ok(Some(Hover { + contents, + range: Some(range) + })) + } + } + + Ok(None) +} + pub fn handle_prepare_rename( world: ServerWorld, params: req::TextDocumentPositionParams, diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index 229d1b0f7..db878e0aa 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs @@ -259,6 +259,7 @@ fn on_request( .on::(handlers::handle_code_action)? .on::(handlers::handle_folding_range)? .on::(handlers::handle_signature_help)? + .on::(handlers::handle_hover)? .on::(handlers::handle_prepare_rename)? .on::(handlers::handle_rename)? .on::(handlers::handle_references)? -- cgit v1.2.3