diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/display/function_signature.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index f16d42276..3d3147254 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs | |||
@@ -84,8 +84,8 @@ impl FunctionSignature { | |||
84 | let ty = field.signature_ty(db); | 84 | let ty = field.signature_ty(db); |
85 | let raw_param = format!("{}", ty.display(db)); | 85 | let raw_param = format!("{}", ty.display(db)); |
86 | 86 | ||
87 | if let Some(param_type) = raw_param.split(':').nth(1) { | 87 | if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) { |
88 | parameter_types.push(param_type[1..].to_string()); | 88 | parameter_types.push(param_type.to_string()); |
89 | } else { | 89 | } else { |
90 | // useful when you have tuple struct | 90 | // useful when you have tuple struct |
91 | parameter_types.push(raw_param.clone()); | 91 | parameter_types.push(raw_param.clone()); |
@@ -129,8 +129,9 @@ impl FunctionSignature { | |||
129 | for field in variant.fields(db).into_iter() { | 129 | for field in variant.fields(db).into_iter() { |
130 | let ty = field.signature_ty(db); | 130 | let ty = field.signature_ty(db); |
131 | let raw_param = format!("{}", ty.display(db)); | 131 | let raw_param = format!("{}", ty.display(db)); |
132 | if let Some(param_type) = raw_param.split(':').nth(1) { | 132 | dbg!(&raw_param); |
133 | parameter_types.push(param_type[1..].to_string()); | 133 | if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) { |
134 | parameter_types.push(param_type.to_string()); | ||
134 | } else { | 135 | } else { |
135 | // The unwrap_or_else is useful when you have tuple | 136 | // The unwrap_or_else is useful when you have tuple |
136 | parameter_types.push(raw_param); | 137 | parameter_types.push(raw_param); |
@@ -197,7 +198,12 @@ impl From<&'_ ast::FnDef> for FunctionSignature { | |||
197 | let raw_param = self_param.syntax().text().to_string(); | 198 | let raw_param = self_param.syntax().text().to_string(); |
198 | 199 | ||
199 | res_types.push( | 200 | res_types.push( |
200 | raw_param.split(':').nth(1).unwrap_or_else(|| " Self")[1..].to_string(), | 201 | raw_param |
202 | .split(':') | ||
203 | .nth(1) | ||
204 | .and_then(|it| it.get(1..)) | ||
205 | .unwrap_or_else(|| "Self") | ||
206 | .to_string(), | ||
201 | ); | 207 | ); |
202 | res.push(raw_param); | 208 | res.push(raw_param); |
203 | } | 209 | } |
@@ -205,8 +211,8 @@ impl From<&'_ ast::FnDef> for FunctionSignature { | |||
205 | res.extend(param_list.params().map(|param| param.syntax().text().to_string())); | 211 | res.extend(param_list.params().map(|param| param.syntax().text().to_string())); |
206 | res_types.extend(param_list.params().map(|param| { | 212 | res_types.extend(param_list.params().map(|param| { |
207 | let param_text = param.syntax().text().to_string(); | 213 | let param_text = param.syntax().text().to_string(); |
208 | match param_text.split(':').nth(1) { | 214 | match param_text.split(':').nth(1).and_then(|it| it.get(1..)) { |
209 | Some(it) => it[1..].to_string(), | 215 | Some(it) => it.to_string(), |
210 | None => param_text, | 216 | None => param_text, |
211 | } | 217 | } |
212 | })); | 218 | })); |