aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/display/function_signature.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/display/function_signature.rs')
-rw-r--r--crates/ra_ide/src/display/function_signature.rs61
1 files changed, 19 insertions, 42 deletions
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs
index 1d39544d3..9b7220d1f 100644
--- a/crates/ra_ide/src/display/function_signature.rs
+++ b/crates/ra_ide/src/display/function_signature.rs
@@ -15,49 +15,48 @@ use stdx::{split_delim, SepBy};
15use crate::display::{generic_parameters, where_predicates}; 15use crate::display::{generic_parameters, where_predicates};
16 16
17#[derive(Debug)] 17#[derive(Debug)]
18pub enum CallableKind { 18pub(crate) enum CallableKind {
19 Function, 19 Function,
20 StructConstructor, 20 StructConstructor,
21 VariantConstructor, 21 VariantConstructor,
22 Macro,
23} 22}
24 23
25/// Contains information about a function signature 24/// Contains information about a function signature
26#[derive(Debug)] 25#[derive(Debug)]
27pub struct FunctionSignature { 26pub(crate) struct FunctionSignature {
28 pub kind: CallableKind, 27 pub(crate) kind: CallableKind,
29 /// Optional visibility 28 /// Optional visibility
30 pub visibility: Option<String>, 29 pub(crate) visibility: Option<String>,
31 /// Qualifiers like `async`, `unsafe`, ... 30 /// Qualifiers like `async`, `unsafe`, ...
32 pub qualifier: FunctionQualifier, 31 pub(crate) qualifier: FunctionQualifier,
33 /// Name of the function 32 /// Name of the function
34 pub name: Option<String>, 33 pub(crate) name: Option<String>,
35 /// Documentation for the function 34 /// Documentation for the function
36 pub doc: Option<Documentation>, 35 pub(crate) doc: Option<Documentation>,
37 /// Generic parameters 36 /// Generic parameters
38 pub generic_parameters: Vec<String>, 37 pub(crate) generic_parameters: Vec<String>,
39 /// Parameters of the function 38 /// Parameters of the function
40 pub parameters: Vec<String>, 39 pub(crate) parameters: Vec<String>,
41 /// Parameter names of the function 40 /// Parameter names of the function
42 pub parameter_names: Vec<String>, 41 pub(crate) parameter_names: Vec<String>,
43 /// Parameter types of the function 42 /// Parameter types of the function
44 pub parameter_types: Vec<String>, 43 pub(crate) parameter_types: Vec<String>,
45 /// Optional return type 44 /// Optional return type
46 pub ret_type: Option<String>, 45 pub(crate) ret_type: Option<String>,
47 /// Where predicates 46 /// Where predicates
48 pub where_predicates: Vec<String>, 47 pub(crate) where_predicates: Vec<String>,
49 /// Self param presence 48 /// Self param presence
50 pub has_self_param: bool, 49 pub(crate) has_self_param: bool,
51} 50}
52 51
53#[derive(Debug, Default)] 52#[derive(Debug, Default)]
54pub struct FunctionQualifier { 53pub(crate) struct FunctionQualifier {
55 // `async` and `const` are mutually exclusive. Do we need to enforcing it here? 54 // `async` and `const` are mutually exclusive. Do we need to enforcing it here?
56 pub is_async: bool, 55 pub(crate) is_async: bool,
57 pub is_const: bool, 56 pub(crate) is_const: bool,
58 pub is_unsafe: bool, 57 pub(crate) is_unsafe: bool,
59 /// The string `extern ".."` 58 /// The string `extern ".."`
60 pub extern_abi: Option<String>, 59 pub(crate) extern_abi: Option<String>,
61} 60}
62 61
63impl FunctionSignature { 62impl FunctionSignature {
@@ -149,27 +148,6 @@ impl FunctionSignature {
149 has_self_param: false, 148 has_self_param: false,
150 }) 149 })
151 } 150 }
152
153 pub(crate) fn from_macro(db: &RootDatabase, macro_def: hir::MacroDef) -> Option<Self> {
154 let node: ast::MacroCall = macro_def.source(db).value;
155
156 let params = vec![];
157
158 Some(FunctionSignature {
159 kind: CallableKind::Macro,
160 visibility: None,
161 qualifier: Default::default(),
162 name: node.name().map(|n| n.text().to_string()),
163 ret_type: None,
164 parameters: params,
165 parameter_names: vec![],
166 parameter_types: vec![],
167 generic_parameters: vec![],
168 where_predicates: vec![],
169 doc: macro_def.docs(db),
170 has_self_param: false,
171 })
172 }
173} 151}
174 152
175impl From<&'_ ast::FnDef> for FunctionSignature { 153impl From<&'_ ast::FnDef> for FunctionSignature {
@@ -298,7 +276,6 @@ impl Display for FunctionSignature {
298 CallableKind::Function => write!(f, "fn {}", name)?, 276 CallableKind::Function => write!(f, "fn {}", name)?,
299 CallableKind::StructConstructor => write!(f, "struct {}", name)?, 277 CallableKind::StructConstructor => write!(f, "struct {}", name)?,
300 CallableKind::VariantConstructor => write!(f, "{}", name)?, 278 CallableKind::VariantConstructor => write!(f, "{}", name)?,
301 CallableKind::Macro => write!(f, "{}!", name)?,
302 } 279 }
303 } 280 }
304 281