aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-08 15:27:44 +0000
committerAleksey Kladov <[email protected]>2019-01-08 15:27:44 +0000
commit256ec6e8d4ac46b2569713d2ffe92d102595f5d2 (patch)
treed28e4a31ff14549d6495f5fa307174d3884a0a08
parente6a4383bb475b866b67df6bb83ecbdf823d73667 (diff)
introduce CallInfo
-rw-r--r--crates/ra_analysis/src/call_info.rs15
-rw-r--r--crates/ra_analysis/src/lib.rs13
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs28
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::{
7use ra_editor::find_node_at_offset; 7use ra_editor::find_node_at_offset;
8use hir::FnSignatureInfo; 8use hir::FnSignatureInfo;
9 9
10use crate::{FilePosition, db::RootDatabase}; 10use crate::{FilePosition, CallInfo, db::RootDatabase};
11
12pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable<Option<CallInfo>> {
13 let (sig_info, active_parameter) = ctry!(call_info_(db, position)?);
14 let res = CallInfo {
15 label: sig_info.label,
16 doc: sig_info.doc,
17 parameters: sig_info.params,
18 active_parameter,
19 };
20 Ok(Some(res))
21}
11 22
12/// Computes parameter information for the given call expression. 23/// Computes parameter information for the given call expression.
13pub(crate) fn call_info( 24fn call_info_(
14 db: &RootDatabase, 25 db: &RootDatabase,
15 position: FilePosition, 26 position: FilePosition,
16) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> { 27) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> {
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<T> RangeInfo<T> {
273 } 273 }
274} 274}
275 275
276#[derive(Debug)]
277pub struct CallInfo {
278 pub label: String,
279 pub doc: Option<String>,
280 pub parameters: Vec<String>,
281 pub active_parameter: Option<usize>,
282}
283
276/// `AnalysisHost` stores the current state of the world. 284/// `AnalysisHost` stores the current state of the world.
277#[derive(Debug, Default)] 285#[derive(Debug, Default)]
278pub struct AnalysisHost { 286pub struct AnalysisHost {
@@ -393,10 +401,7 @@ impl Analysis {
393 hover::hover(&*self.db, position) 401 hover::hover(&*self.db, position)
394 } 402 }
395 /// Computes parameter information for the given call expression. 403 /// Computes parameter information for the given call expression.
396 pub fn call_info( 404 pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> {
397 &self,
398 position: FilePosition,
399 ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> {
400 call_info::call_info(&*self.db, position) 405 call_info::call_info(&*self.db, position)
401 } 406 }
402 /// Returns a `mod name;` declaration which created the current module. 407 /// 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(
475 params: req::TextDocumentPositionParams, 475 params: req::TextDocumentPositionParams,
476) -> Result<Option<req::SignatureHelp>> { 476) -> Result<Option<req::SignatureHelp>> {
477 let position = params.try_conv_with(&world)?; 477 let position = params.try_conv_with(&world)?;
478 478 if let Some(call_info) = world.analysis().call_info(position)? {
479 if let Some((descriptor, active_param)) = world.analysis().resolve_callable(position)? { 479 let parameters: Vec<ParameterInformation> = call_info
480 let parameters: Vec<ParameterInformation> = descriptor 480 .parameters
481 .params 481 .into_iter()
482 .iter()
483 .map(|param| ParameterInformation { 482 .map(|param| ParameterInformation {
484 label: ParameterLabel::Simple(param.clone()), 483 label: ParameterLabel::Simple(param.clone()),
485 documentation: None, 484 documentation: None,
486 }) 485 })
487 .collect(); 486 .collect();
488 487 let documentation = call_info.doc.map(|value| {
489 let documentation = if let Some(doc) = descriptor.doc { 488 Documentation::MarkupContent(MarkupContent {
490 Some(Documentation::MarkupContent(MarkupContent {
491 kind: MarkupKind::Markdown, 489 kind: MarkupKind::Markdown,
492 value: doc, 490 value,
493 })) 491 })
494 } else { 492 });
495 None
496 };
497
498 let sig_info = SignatureInformation { 493 let sig_info = SignatureInformation {
499 label: descriptor.label, 494 label: call_info.label,
500 documentation, 495 documentation,
501 parameters: Some(parameters), 496 parameters: Some(parameters),
502 }; 497 };
503
504 Ok(Some(req::SignatureHelp { 498 Ok(Some(req::SignatureHelp {
505 signatures: vec![sig_info], 499 signatures: vec![sig_info],
506 active_signature: Some(0), 500 active_signature: Some(0),
507 active_parameter: active_param.map(|a| a as u64), 501 active_parameter: call_info.active_parameter.map(|it| it as u64),
508 })) 502 }))
509 } else { 503 } else {
510 Ok(None) 504 Ok(None)