diff options
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop/handlers.rs')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 29 |
1 files changed, 27 insertions, 2 deletions
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; | |||
4 | use languageserver_types::{ | 4 | use languageserver_types::{ |
5 | CodeActionResponse, Command, CompletionItem, CompletionItemKind, Diagnostic, | 5 | CodeActionResponse, Command, CompletionItem, CompletionItemKind, Diagnostic, |
6 | DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind, | 6 | DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind, |
7 | FoldingRangeParams, InsertTextFormat, Location, MarkupContent, MarkupKind, Position, | 7 | FoldingRangeParams, InsertTextFormat, Location, MarkupContent, MarkupKind, MarkedString, Position, |
8 | PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, | 8 | PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, |
9 | WorkspaceEdit, ParameterInformation, SignatureInformation, | 9 | WorkspaceEdit, ParameterInformation, SignatureInformation, Hover, HoverContents, |
10 | }; | 10 | }; |
11 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; | 11 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; |
12 | use ra_syntax::text_utils::contains_offset_nonstrict; | 12 | use ra_syntax::text_utils::contains_offset_nonstrict; |
@@ -478,6 +478,31 @@ pub fn handle_signature_help( | |||
478 | } | 478 | } |
479 | } | 479 | } |
480 | 480 | ||
481 | pub fn handle_hover( | ||
482 | world: ServerWorld, | ||
483 | params: req::TextDocumentPositionParams, | ||
484 | ) -> Result<Option<Hover>> { | ||
485 | let position = params.try_conv_with(&world)?; | ||
486 | let line_index = world.analysis().file_line_index(position.file_id); | ||
487 | |||
488 | for (file_id, symbol) in world.analysis().approximately_resolve_symbol(position)? { | ||
489 | let range = symbol.node_range.conv_with(&line_index); | ||
490 | let name = symbol.name.to_string(); | ||
491 | let comment = world.analysis.doc_comment_for(file_id, symbol)?; | ||
492 | |||
493 | if comment.is_some() { | ||
494 | let contents = HoverContents::Scalar(MarkedString::String(comment.unwrap())); | ||
495 | |||
496 | return Ok(Some(Hover { | ||
497 | contents, | ||
498 | range: Some(range) | ||
499 | })) | ||
500 | } | ||
501 | } | ||
502 | |||
503 | Ok(None) | ||
504 | } | ||
505 | |||
481 | pub fn handle_prepare_rename( | 506 | pub fn handle_prepare_rename( |
482 | world: ServerWorld, | 507 | world: ServerWorld, |
483 | params: req::TextDocumentPositionParams, | 508 | params: req::TextDocumentPositionParams, |