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.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs
index e58a78271..2d175882b 100644
--- a/crates/ra_ide/src/display/function_signature.rs
+++ b/crates/ra_ide/src/display/function_signature.rs
@@ -69,7 +69,13 @@ impl FunctionSignature {
69 for field in st.fields(db).into_iter() { 69 for field in st.fields(db).into_iter() {
70 let ty = field.signature_ty(db); 70 let ty = field.signature_ty(db);
71 let raw_param = format!("{}", ty.display(db)); 71 let raw_param = format!("{}", ty.display(db));
72 parameter_types.push(raw_param.split(':').nth(1).unwrap()[1..].to_string()); 72
73 if let Some(param_type) = raw_param.split(':').nth(1) {
74 parameter_types.push(param_type[1..].to_string());
75 } else {
76 // The unwrap_or_else is useful when you have tuple struct
77 parameter_types.push(raw_param.clone());
78 }
73 params.push(raw_param); 79 params.push(raw_param);
74 } 80 }
75 81
@@ -107,8 +113,15 @@ impl FunctionSignature {
107 for field in variant.fields(db).into_iter() { 113 for field in variant.fields(db).into_iter() {
108 let ty = field.signature_ty(db); 114 let ty = field.signature_ty(db);
109 let raw_param = format!("{}", ty.display(db)); 115 let raw_param = format!("{}", ty.display(db));
110 parameter_types.push(raw_param.split(':').nth(1).unwrap()[1..].to_string()); 116 if let Some(param_type) = raw_param.split(':').nth(1) {
111 params.push(raw_param); 117 parameter_types.push(param_type[1..].to_string());
118 } else {
119 // The unwrap_or_else is useful when you have tuple
120 parameter_types.push(raw_param);
121 }
122 let name = field.name(db);
123
124 params.push(format!("{}: {}", name, ty.display(db)));
112 } 125 }
113 126
114 Some( 127 Some(
@@ -164,7 +177,7 @@ impl From<&'_ ast::FnDef> for FunctionSignature {
164 has_self_param = true; 177 has_self_param = true;
165 let raw_param = self_param.syntax().text().to_string(); 178 let raw_param = self_param.syntax().text().to_string();
166 179
167 // TODO: better solution ? 180 // FIXME: better solution ?
168 res_types.push( 181 res_types.push(
169 raw_param.split(':').nth(1).unwrap_or_else(|| " Self")[1..].to_string(), 182 raw_param.split(':').nth(1).unwrap_or_else(|| " Self")[1..].to_string(),
170 ); 183 );