mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Hot fix panic for function_signature
This commit is contained in:
parent
f1cb5b8a29
commit
9405116d51
1 changed files with 13 additions and 7 deletions
|
@ -84,8 +84,8 @@ impl FunctionSignature {
|
||||||
let ty = field.signature_ty(db);
|
let ty = field.signature_ty(db);
|
||||||
let raw_param = format!("{}", ty.display(db));
|
let raw_param = format!("{}", ty.display(db));
|
||||||
|
|
||||||
if let Some(param_type) = raw_param.split(':').nth(1) {
|
if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) {
|
||||||
parameter_types.push(param_type[1..].to_string());
|
parameter_types.push(param_type.to_string());
|
||||||
} else {
|
} else {
|
||||||
// useful when you have tuple struct
|
// useful when you have tuple struct
|
||||||
parameter_types.push(raw_param.clone());
|
parameter_types.push(raw_param.clone());
|
||||||
|
@ -129,8 +129,9 @@ impl FunctionSignature {
|
||||||
for field in variant.fields(db).into_iter() {
|
for field in variant.fields(db).into_iter() {
|
||||||
let ty = field.signature_ty(db);
|
let ty = field.signature_ty(db);
|
||||||
let raw_param = format!("{}", ty.display(db));
|
let raw_param = format!("{}", ty.display(db));
|
||||||
if let Some(param_type) = raw_param.split(':').nth(1) {
|
dbg!(&raw_param);
|
||||||
parameter_types.push(param_type[1..].to_string());
|
if let Some(param_type) = raw_param.split(':').nth(1).and_then(|it| it.get(1..)) {
|
||||||
|
parameter_types.push(param_type.to_string());
|
||||||
} else {
|
} else {
|
||||||
// The unwrap_or_else is useful when you have tuple
|
// The unwrap_or_else is useful when you have tuple
|
||||||
parameter_types.push(raw_param);
|
parameter_types.push(raw_param);
|
||||||
|
@ -197,7 +198,12 @@ impl From<&'_ ast::FnDef> for FunctionSignature {
|
||||||
let raw_param = self_param.syntax().text().to_string();
|
let raw_param = self_param.syntax().text().to_string();
|
||||||
|
|
||||||
res_types.push(
|
res_types.push(
|
||||||
raw_param.split(':').nth(1).unwrap_or_else(|| " Self")[1..].to_string(),
|
raw_param
|
||||||
|
.split(':')
|
||||||
|
.nth(1)
|
||||||
|
.and_then(|it| it.get(1..))
|
||||||
|
.unwrap_or_else(|| "Self")
|
||||||
|
.to_string(),
|
||||||
);
|
);
|
||||||
res.push(raw_param);
|
res.push(raw_param);
|
||||||
}
|
}
|
||||||
|
@ -205,8 +211,8 @@ impl From<&'_ ast::FnDef> for FunctionSignature {
|
||||||
res.extend(param_list.params().map(|param| param.syntax().text().to_string()));
|
res.extend(param_list.params().map(|param| param.syntax().text().to_string()));
|
||||||
res_types.extend(param_list.params().map(|param| {
|
res_types.extend(param_list.params().map(|param| {
|
||||||
let param_text = param.syntax().text().to_string();
|
let param_text = param.syntax().text().to_string();
|
||||||
match param_text.split(':').nth(1) {
|
match param_text.split(':').nth(1).and_then(|it| it.get(1..)) {
|
||||||
Some(it) => it[1..].to_string(),
|
Some(it) => it.to_string(),
|
||||||
None => param_text,
|
None => param_text,
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in a new issue