diff options
author | Benjamin Coenen <[email protected]> | 2020-05-10 11:31:55 +0100 |
---|---|---|
committer | Benjamin Coenen <[email protected]> | 2020-05-10 11:31:55 +0100 |
commit | e80903a96564c2239489a8c630a4748bf21a3659 (patch) | |
tree | 12b31a1fd12deb2120065cea5a558425c8c1984f /crates/ra_ide/src/display | |
parent | 6203e9c4faee288f16d93dbb7dd0f1f8df487d83 (diff) | |
parent | 4578154b608fa075595103d0c933da60d55b25c8 (diff) |
Merge branch 'master' of github.com:rust-analyzer/rust-analyzer into feat_4348
Diffstat (limited to 'crates/ra_ide/src/display')
-rw-r--r-- | crates/ra_ide/src/display/function_signature.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index db3907fe6..9572debd8 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs | |||
@@ -1,5 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | // FIXME: this modules relies on strings and AST way too much, and it should be | ||
4 | // rewritten (matklad 2020-05-07) | ||
3 | use std::{ | 5 | use std::{ |
4 | convert::From, | 6 | convert::From, |
5 | fmt::{self, Display}, | 7 | fmt::{self, Display}, |
@@ -82,8 +84,8 @@ impl FunctionSignature { | |||
82 | let ty = field.signature_ty(db); | 84 | let ty = field.signature_ty(db); |
83 | let raw_param = format!("{}", ty.display(db)); | 85 | let raw_param = format!("{}", ty.display(db)); |
84 | 86 | ||
85 | 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..)) { |
86 | parameter_types.push(param_type[1..].to_string()); | 88 | parameter_types.push(param_type.to_string()); |
87 | } else { | 89 | } else { |
88 | // useful when you have tuple struct | 90 | // useful when you have tuple struct |
89 | parameter_types.push(raw_param.clone()); | 91 | parameter_types.push(raw_param.clone()); |
@@ -127,8 +129,8 @@ impl FunctionSignature { | |||
127 | for field in variant.fields(db).into_iter() { | 129 | for field in variant.fields(db).into_iter() { |
128 | let ty = field.signature_ty(db); | 130 | let ty = field.signature_ty(db); |
129 | let raw_param = format!("{}", ty.display(db)); | 131 | let raw_param = format!("{}", ty.display(db)); |
130 | if let Some(param_type) = raw_param.split(':').nth(1) { | 132 | if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) { |
131 | parameter_types.push(param_type[1..].to_string()); | 133 | parameter_types.push(param_type.to_string()); |
132 | } else { | 134 | } else { |
133 | // The unwrap_or_else is useful when you have tuple | 135 | // The unwrap_or_else is useful when you have tuple |
134 | parameter_types.push(raw_param); | 136 | parameter_types.push(raw_param); |
@@ -195,14 +197,23 @@ impl From<&'_ ast::FnDef> for FunctionSignature { | |||
195 | let raw_param = self_param.syntax().text().to_string(); | 197 | let raw_param = self_param.syntax().text().to_string(); |
196 | 198 | ||
197 | res_types.push( | 199 | res_types.push( |
198 | raw_param.split(':').nth(1).unwrap_or_else(|| " Self")[1..].to_string(), | 200 | raw_param |
201 | .split(':') | ||
202 | .nth(1) | ||
203 | .and_then(|it| it.get(1..)) | ||
204 | .unwrap_or_else(|| "Self") | ||
205 | .to_string(), | ||
199 | ); | 206 | ); |
200 | res.push(raw_param); | 207 | res.push(raw_param); |
201 | } | 208 | } |
202 | 209 | ||
203 | res.extend(param_list.params().map(|param| param.syntax().text().to_string())); | 210 | res.extend(param_list.params().map(|param| param.syntax().text().to_string())); |
204 | res_types.extend(param_list.params().map(|param| { | 211 | res_types.extend(param_list.params().map(|param| { |
205 | param.syntax().text().to_string().split(':').nth(1).unwrap()[1..].to_string() | 212 | let param_text = param.syntax().text().to_string(); |
213 | match param_text.split(':').nth(1).and_then(|it| it.get(1..)) { | ||
214 | Some(it) => it.to_string(), | ||
215 | None => param_text, | ||
216 | } | ||
206 | })); | 217 | })); |
207 | } | 218 | } |
208 | (has_self_param, res, res_types) | 219 | (has_self_param, res, res_types) |