aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVille Penttinen <[email protected]>2019-04-08 08:46:26 +0100
committerVille Penttinen <[email protected]>2019-04-09 12:45:05 +0100
commitdfaebd76aba1cfd7ac13b940d7847eb44b953cac (patch)
tree1d3e6d2a6809ad3786880dade195bf8cd9a24560
parent2fe075f56eff65ee6d326f7ea8bc0efccc4df152 (diff)
Add FunctionSignature::from_hir
-rw-r--r--crates/ra_ide_api/src/call_info.rs10
-rw-r--r--crates/ra_ide_api/src/display.rs7
2 files changed, 11 insertions, 6 deletions
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs
index 66a769c73..dbb3853d0 100644
--- a/crates/ra_ide_api/src/call_info.rs
+++ b/crates/ra_ide_api/src/call_info.rs
@@ -6,7 +6,6 @@ use ra_syntax::{
6 ast::{self, ArgListOwner}, 6 ast::{self, ArgListOwner},
7 algo::find_node_at_offset, 7 algo::find_node_at_offset,
8}; 8};
9use hir::Docs;
10 9
11use crate::{FilePosition, CallInfo, FunctionSignature, db::RootDatabase}; 10use crate::{FilePosition, CallInfo, FunctionSignature, db::RootDatabase};
12 11
@@ -27,7 +26,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
27 let fn_def = ast::FnDef::cast(fn_def).unwrap(); 26 let fn_def = ast::FnDef::cast(fn_def).unwrap();
28 let function = hir::source_binder::function_from_source(db, symbol.file_id, fn_def)?; 27 let function = hir::source_binder::function_from_source(db, symbol.file_id, fn_def)?;
29 28
30 let mut call_info = CallInfo::new(db, function, fn_def)?; 29 let mut call_info = CallInfo::new(db, function);
31 30
32 // If we have a calling expression let's find which argument we are on 31 // If we have a calling expression let's find which argument we are on
33 let num_params = call_info.parameters().len(); 32 let num_params = call_info.parameters().len();
@@ -107,11 +106,10 @@ impl<'a> FnCallNode<'a> {
107} 106}
108 107
109impl CallInfo { 108impl CallInfo {
110 fn new(db: &RootDatabase, function: hir::Function, node: &ast::FnDef) -> Option<Self> { 109 fn new(db: &RootDatabase, function: hir::Function) -> Self {
111 let doc = function.docs(db); 110 let signature = FunctionSignature::from_hir(db, function);
112 let signature = FunctionSignature::from(node).with_doc_opt(doc);
113 111
114 Some(CallInfo { signature, active_parameter: None }) 112 CallInfo { signature, active_parameter: None }
115 } 113 }
116 114
117 fn parameters(&self) -> &[String] { 115 fn parameters(&self) -> &[String] {
diff --git a/crates/ra_ide_api/src/display.rs b/crates/ra_ide_api/src/display.rs
index 4ce362ebb..c05d59689 100644
--- a/crates/ra_ide_api/src/display.rs
+++ b/crates/ra_ide_api/src/display.rs
@@ -5,6 +5,7 @@ use std::fmt::{self, Display};
5use join_to_string::join; 5use join_to_string::join;
6use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner, TypeParamsOwner}; 6use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner, TypeParamsOwner};
7use std::convert::From; 7use std::convert::From;
8use hir::Docs;
8 9
9/// Contains information about a function signature 10/// Contains information about a function signature
10#[derive(Debug)] 11#[derive(Debug)]
@@ -30,6 +31,12 @@ impl FunctionSignature {
30 self.doc = doc; 31 self.doc = doc;
31 self 32 self
32 } 33 }
34
35 pub(crate) fn from_hir(db: &db::RootDatabase, function: hir::Function) -> Self {
36 let doc = function.docs(db);
37 let (_, ast_node) = function.source(db);
38 FunctionSignature::from(&*ast_node).with_doc_opt(doc)
39 }
33} 40}
34 41
35impl From<&'_ ast::FnDef> for FunctionSignature { 42impl From<&'_ ast::FnDef> for FunctionSignature {