From 256ec6e8d4ac46b2569713d2ffe92d102595f5d2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 8 Jan 2019 18:27:44 +0300 Subject: introduce CallInfo --- crates/ra_analysis/src/call_info.rs | 15 ++++++++++++-- crates/ra_analysis/src/lib.rs | 13 ++++++++---- crates/ra_lsp_server/src/main_loop/handlers.rs | 28 ++++++++++---------------- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/crates/ra_analysis/src/call_info.rs b/crates/ra_analysis/src/call_info.rs index a31a54ef6..8da19a648 100644 --- a/crates/ra_analysis/src/call_info.rs +++ b/crates/ra_analysis/src/call_info.rs @@ -7,10 +7,21 @@ use ra_syntax::{ use ra_editor::find_node_at_offset; use hir::FnSignatureInfo; -use crate::{FilePosition, db::RootDatabase}; +use crate::{FilePosition, CallInfo, db::RootDatabase}; + +pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable> { + let (sig_info, active_parameter) = ctry!(call_info_(db, position)?); + let res = CallInfo { + label: sig_info.label, + doc: sig_info.doc, + parameters: sig_info.params, + active_parameter, + }; + Ok(Some(res)) +} /// Computes parameter information for the given call expression. -pub(crate) fn call_info( +fn call_info_( db: &RootDatabase, position: FilePosition, ) -> Cancelable)>> { diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 9192f66e8..4fa6750aa 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -273,6 +273,14 @@ impl RangeInfo { } } +#[derive(Debug)] +pub struct CallInfo { + pub label: String, + pub doc: Option, + pub parameters: Vec, + pub active_parameter: Option, +} + /// `AnalysisHost` stores the current state of the world. #[derive(Debug, Default)] pub struct AnalysisHost { @@ -393,10 +401,7 @@ impl Analysis { hover::hover(&*self.db, position) } /// Computes parameter information for the given call expression. - pub fn call_info( - &self, - position: FilePosition, - ) -> Cancelable)>> { + pub fn call_info(&self, position: FilePosition) -> Cancelable> { call_info::call_info(&*self.db, position) } /// Returns a `mod name;` declaration which created the current module. diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 99f15354f..b9b42f1b3 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -475,36 +475,30 @@ pub fn handle_signature_help( params: req::TextDocumentPositionParams, ) -> Result> { let position = params.try_conv_with(&world)?; - - if let Some((descriptor, active_param)) = world.analysis().resolve_callable(position)? { - let parameters: Vec = descriptor - .params - .iter() + 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 documentation = if let Some(doc) = descriptor.doc { - Some(Documentation::MarkupContent(MarkupContent { + let documentation = call_info.doc.map(|value| { + Documentation::MarkupContent(MarkupContent { kind: MarkupKind::Markdown, - value: doc, - })) - } else { - None - }; - + value, + }) + }); let sig_info = SignatureInformation { - label: descriptor.label, + label: call_info.label, documentation, parameters: Some(parameters), }; - Ok(Some(req::SignatureHelp { signatures: vec![sig_info], active_signature: Some(0), - active_parameter: active_param.map(|a| a as u64), + active_parameter: call_info.active_parameter.map(|it| it as u64), })) } else { Ok(None) -- cgit v1.2.3