From 0e49abb7fbe9239b97f0b7168ec359014c63f8c0 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Tue, 12 Mar 2019 09:24:46 +0200 Subject: Refactor CallInfo function signatures to new FunctionSignature type This is used by CallInfo to create a pretty printed function signature that can be used with completions and other places as well. --- crates/ra_lsp_server/src/conv.rs | 22 ++++++++++++++++++++++ crates/ra_lsp_server/src/main_loop/handlers.rs | 23 +++++------------------ 2 files changed, 27 insertions(+), 18 deletions(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 74e91c236..4d6ede316 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -174,6 +174,28 @@ impl Conv for ra_ide_api::Documentation { } } +impl Conv for ra_ide_api::FunctionSignature { + type Output = lsp_types::SignatureInformation; + fn conv(self) -> Self::Output { + use lsp_types::{ParameterInformation, ParameterLabel, SignatureInformation}; + + let label = self.to_string(); + + let documentation = self.doc.map(|it| it.conv()); + + let parameters: Vec = self + .parameters + .into_iter() + .map(|param| ParameterInformation { + label: ParameterLabel::Simple(param), + documentation: None, + }) + .collect(); + + SignatureInformation { label, documentation, parameters: Some(parameters) } + } +} + impl ConvWith for TextEdit { type Ctx = LineIndex; type Output = Vec; diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 89e96a33a..b96deb061 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -3,8 +3,8 @@ use lsp_types::{ CodeActionResponse, CodeLens, Command, Diagnostic, DiagnosticSeverity, CodeAction, DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, - MarkupKind, ParameterInformation, ParameterLabel, Position, PrepareRenameResponse, Range, - RenameParams, SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, + MarkupKind, Position, PrepareRenameResponse, Range, + RenameParams,SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit, }; use ra_ide_api::{ @@ -403,26 +403,13 @@ pub fn handle_signature_help( ) -> Result> { let position = params.try_conv_with(&world)?; if let Some(call_info) = world.analysis().call_info(position)? { - let parameters: Vec = call_info - .parameters - .into_iter() - .map(|param| ParameterInformation { - label: ParameterLabel::Simple(param.clone()), - documentation: None, - }) - .collect(); + let active_parameter = call_info.active_parameter.map(|it| it as i64); + let sig_info = call_info.signature.conv(); - let documentation = call_info.doc.map(|it| it.conv()); - - let sig_info = SignatureInformation { - label: call_info.label, - documentation, - parameters: Some(parameters), - }; Ok(Some(req::SignatureHelp { signatures: vec![sig_info], active_signature: Some(0), - active_parameter: call_info.active_parameter.map(|it| it as i64), + active_parameter, })) } else { Ok(None) -- cgit v1.2.3