diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-23 10:09:35 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-23 10:09:35 +0000 |
commit | 838ad6bcfb2a82c030e18d019b8a06752f0fc828 (patch) | |
tree | 8291c9a198751b4c31e4de0dbf6cb3d7b69c723c /crates/ra_ide/src/display | |
parent | 58d44c6ba2de32a31a09bbcaf61365a69b69374c (diff) | |
parent | b2a7b29bb9e195e75ad04dc69c572d02f98fe5ce (diff) |
Merge #3279
3279: Add basic parameter name hints heuristics r=matklad a=SomeoneToIgnore
Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/display')
-rw-r--r-- | crates/ra_ide/src/display/function_signature.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index b85fd8075..2c4c932de 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs | |||
@@ -38,6 +38,8 @@ pub struct FunctionSignature { | |||
38 | pub ret_type: Option<String>, | 38 | pub ret_type: Option<String>, |
39 | /// Where predicates | 39 | /// Where predicates |
40 | pub where_predicates: Vec<String>, | 40 | pub where_predicates: Vec<String>, |
41 | /// Self param presence | ||
42 | pub has_self_param: bool, | ||
41 | } | 43 | } |
42 | 44 | ||
43 | impl FunctionSignature { | 45 | impl FunctionSignature { |
@@ -78,6 +80,7 @@ impl FunctionSignature { | |||
78 | generic_parameters: generic_parameters(&node), | 80 | generic_parameters: generic_parameters(&node), |
79 | where_predicates: where_predicates(&node), | 81 | where_predicates: where_predicates(&node), |
80 | doc: None, | 82 | doc: None, |
83 | has_self_param: false, | ||
81 | } | 84 | } |
82 | .with_doc_opt(st.docs(db)), | 85 | .with_doc_opt(st.docs(db)), |
83 | ) | 86 | ) |
@@ -115,6 +118,7 @@ impl FunctionSignature { | |||
115 | generic_parameters: vec![], | 118 | generic_parameters: vec![], |
116 | where_predicates: vec![], | 119 | where_predicates: vec![], |
117 | doc: None, | 120 | doc: None, |
121 | has_self_param: false, | ||
118 | } | 122 | } |
119 | .with_doc_opt(variant.docs(db)), | 123 | .with_doc_opt(variant.docs(db)), |
120 | ) | 124 | ) |
@@ -136,6 +140,7 @@ impl FunctionSignature { | |||
136 | generic_parameters: vec![], | 140 | generic_parameters: vec![], |
137 | where_predicates: vec![], | 141 | where_predicates: vec![], |
138 | doc: None, | 142 | doc: None, |
143 | has_self_param: false, | ||
139 | } | 144 | } |
140 | .with_doc_opt(macro_def.docs(db)), | 145 | .with_doc_opt(macro_def.docs(db)), |
141 | ) | 146 | ) |
@@ -144,16 +149,18 @@ impl FunctionSignature { | |||
144 | 149 | ||
145 | impl From<&'_ ast::FnDef> for FunctionSignature { | 150 | impl From<&'_ ast::FnDef> for FunctionSignature { |
146 | fn from(node: &ast::FnDef) -> FunctionSignature { | 151 | fn from(node: &ast::FnDef) -> FunctionSignature { |
147 | fn param_list(node: &ast::FnDef) -> Vec<String> { | 152 | fn param_list(node: &ast::FnDef) -> (bool, Vec<String>) { |
148 | let mut res = vec![]; | 153 | let mut res = vec![]; |
154 | let mut has_self_param = false; | ||
149 | if let Some(param_list) = node.param_list() { | 155 | if let Some(param_list) = node.param_list() { |
150 | if let Some(self_param) = param_list.self_param() { | 156 | if let Some(self_param) = param_list.self_param() { |
157 | has_self_param = true; | ||
151 | res.push(self_param.syntax().text().to_string()) | 158 | res.push(self_param.syntax().text().to_string()) |
152 | } | 159 | } |
153 | 160 | ||
154 | res.extend(param_list.params().map(|param| param.syntax().text().to_string())); | 161 | res.extend(param_list.params().map(|param| param.syntax().text().to_string())); |
155 | } | 162 | } |
156 | res | 163 | (has_self_param, res) |
157 | } | 164 | } |
158 | 165 | ||
159 | fn param_name_list(node: &ast::FnDef) -> Vec<String> { | 166 | fn param_name_list(node: &ast::FnDef) -> Vec<String> { |
@@ -183,6 +190,8 @@ impl From<&'_ ast::FnDef> for FunctionSignature { | |||
183 | res | 190 | res |
184 | } | 191 | } |
185 | 192 | ||
193 | let (has_self_param, parameters) = param_list(node); | ||
194 | |||
186 | FunctionSignature { | 195 | FunctionSignature { |
187 | kind: CallableKind::Function, | 196 | kind: CallableKind::Function, |
188 | visibility: node.visibility().map(|n| n.syntax().text().to_string()), | 197 | visibility: node.visibility().map(|n| n.syntax().text().to_string()), |
@@ -191,12 +200,13 @@ impl From<&'_ ast::FnDef> for FunctionSignature { | |||
191 | .ret_type() | 200 | .ret_type() |
192 | .and_then(|r| r.type_ref()) | 201 | .and_then(|r| r.type_ref()) |
193 | .map(|n| n.syntax().text().to_string()), | 202 | .map(|n| n.syntax().text().to_string()), |
194 | parameters: param_list(node), | 203 | parameters, |
195 | parameter_names: param_name_list(node), | 204 | parameter_names: param_name_list(node), |
196 | generic_parameters: generic_parameters(node), | 205 | generic_parameters: generic_parameters(node), |
197 | where_predicates: where_predicates(node), | 206 | where_predicates: where_predicates(node), |
198 | // docs are processed separately | 207 | // docs are processed separately |
199 | doc: None, | 208 | doc: None, |
209 | has_self_param, | ||
200 | } | 210 | } |
201 | } | 211 | } |
202 | } | 212 | } |