diff options
Diffstat (limited to 'crates/ra_ide/src/display/function_signature.rs')
-rw-r--r-- | crates/ra_ide/src/display/function_signature.rs | 107 |
1 files changed, 47 insertions, 60 deletions
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index a98264fb3..1d39544d3 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs | |||
@@ -61,15 +61,11 @@ pub struct FunctionQualifier { | |||
61 | } | 61 | } |
62 | 62 | ||
63 | impl FunctionSignature { | 63 | impl FunctionSignature { |
64 | pub(crate) fn with_doc_opt(mut self, doc: Option<Documentation>) -> Self { | ||
65 | self.doc = doc; | ||
66 | self | ||
67 | } | ||
68 | |||
69 | pub(crate) fn from_hir(db: &RootDatabase, function: hir::Function) -> Self { | 64 | pub(crate) fn from_hir(db: &RootDatabase, function: hir::Function) -> Self { |
70 | let doc = function.docs(db); | ||
71 | let ast_node = function.source(db).value; | 65 | let ast_node = function.source(db).value; |
72 | FunctionSignature::from(&ast_node).with_doc_opt(doc) | 66 | let mut res = FunctionSignature::from(&ast_node); |
67 | res.doc = function.docs(db); | ||
68 | res | ||
73 | } | 69 | } |
74 | 70 | ||
75 | pub(crate) fn from_struct(db: &RootDatabase, st: hir::Struct) -> Option<Self> { | 71 | pub(crate) fn from_struct(db: &RootDatabase, st: hir::Struct) -> Option<Self> { |
@@ -93,24 +89,21 @@ impl FunctionSignature { | |||
93 | params.push(raw_param); | 89 | params.push(raw_param); |
94 | } | 90 | } |
95 | 91 | ||
96 | Some( | 92 | Some(FunctionSignature { |
97 | FunctionSignature { | 93 | kind: CallableKind::StructConstructor, |
98 | kind: CallableKind::StructConstructor, | 94 | visibility: node.visibility().map(|n| n.syntax().text().to_string()), |
99 | visibility: node.visibility().map(|n| n.syntax().text().to_string()), | 95 | // Do we need `const`? |
100 | // Do we need `const`? | 96 | qualifier: Default::default(), |
101 | qualifier: Default::default(), | 97 | name: node.name().map(|n| n.text().to_string()), |
102 | name: node.name().map(|n| n.text().to_string()), | 98 | ret_type: node.name().map(|n| n.text().to_string()), |
103 | ret_type: node.name().map(|n| n.text().to_string()), | 99 | parameters: params, |
104 | parameters: params, | 100 | parameter_names: vec![], |
105 | parameter_names: vec![], | 101 | parameter_types, |
106 | parameter_types, | 102 | generic_parameters: generic_parameters(&node), |
107 | generic_parameters: generic_parameters(&node), | 103 | where_predicates: where_predicates(&node), |
108 | where_predicates: where_predicates(&node), | 104 | doc: st.docs(db), |
109 | doc: None, | 105 | has_self_param: false, |
110 | has_self_param: false, | 106 | }) |
111 | } | ||
112 | .with_doc_opt(st.docs(db)), | ||
113 | ) | ||
114 | } | 107 | } |
115 | 108 | ||
116 | pub(crate) fn from_enum_variant(db: &RootDatabase, variant: hir::EnumVariant) -> Option<Self> { | 109 | pub(crate) fn from_enum_variant(db: &RootDatabase, variant: hir::EnumVariant) -> Option<Self> { |
@@ -140,24 +133,21 @@ impl FunctionSignature { | |||
140 | params.push(format!("{}: {}", name, ty.display(db))); | 133 | params.push(format!("{}: {}", name, ty.display(db))); |
141 | } | 134 | } |
142 | 135 | ||
143 | Some( | 136 | Some(FunctionSignature { |
144 | FunctionSignature { | 137 | kind: CallableKind::VariantConstructor, |
145 | kind: CallableKind::VariantConstructor, | 138 | visibility: None, |
146 | visibility: None, | 139 | // Do we need `const`? |
147 | // Do we need `const`? | 140 | qualifier: Default::default(), |
148 | qualifier: Default::default(), | 141 | name: Some(name), |
149 | name: Some(name), | 142 | ret_type: None, |
150 | ret_type: None, | 143 | parameters: params, |
151 | parameters: params, | 144 | parameter_names: vec![], |
152 | parameter_names: vec![], | 145 | parameter_types, |
153 | parameter_types, | 146 | generic_parameters: vec![], |
154 | generic_parameters: vec![], | 147 | where_predicates: vec![], |
155 | where_predicates: vec![], | 148 | doc: variant.docs(db), |
156 | doc: None, | 149 | has_self_param: false, |
157 | has_self_param: false, | 150 | }) |
158 | } | ||
159 | .with_doc_opt(variant.docs(db)), | ||
160 | ) | ||
161 | } | 151 | } |
162 | 152 | ||
163 | pub(crate) fn from_macro(db: &RootDatabase, macro_def: hir::MacroDef) -> Option<Self> { | 153 | pub(crate) fn from_macro(db: &RootDatabase, macro_def: hir::MacroDef) -> Option<Self> { |
@@ -165,23 +155,20 @@ impl FunctionSignature { | |||
165 | 155 | ||
166 | let params = vec![]; | 156 | let params = vec![]; |
167 | 157 | ||
168 | Some( | 158 | Some(FunctionSignature { |
169 | FunctionSignature { | 159 | kind: CallableKind::Macro, |
170 | kind: CallableKind::Macro, | 160 | visibility: None, |
171 | visibility: None, | 161 | qualifier: Default::default(), |
172 | qualifier: Default::default(), | 162 | name: node.name().map(|n| n.text().to_string()), |
173 | name: node.name().map(|n| n.text().to_string()), | 163 | ret_type: None, |
174 | ret_type: None, | 164 | parameters: params, |
175 | parameters: params, | 165 | parameter_names: vec![], |
176 | parameter_names: vec![], | 166 | parameter_types: vec![], |
177 | parameter_types: vec![], | 167 | generic_parameters: vec![], |
178 | generic_parameters: vec![], | 168 | where_predicates: vec![], |
179 | where_predicates: vec![], | 169 | doc: macro_def.docs(db), |
180 | doc: None, | 170 | has_self_param: false, |
181 | has_self_param: false, | 171 | }) |
182 | } | ||
183 | .with_doc_opt(macro_def.docs(db)), | ||
184 | ) | ||
185 | } | 172 | } |
186 | } | 173 | } |
187 | 174 | ||