Merge #4409
4409: Hot fix panic for function_signature r=edwin0cheng a=edwin0cheng
I am totally agree this comment:
f1cb5b8a29/crates/ra_ide/src/display/function_signature.rs (L3-L4)
But let hot fix all panic for right now, it is so disturbing when browsing code...
Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
This commit is contained in:
commit
4578154b60
@ -84,8 +84,8 @@ pub(crate) fn from_struct(db: &RootDatabase, st: hir::Struct) -> Option<Self> {
|
||||
let ty = field.signature_ty(db);
|
||||
let raw_param = format!("{}", ty.display(db));
|
||||
|
||||
if let Some(param_type) = raw_param.split(':').nth(1) {
|
||||
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 {
|
||||
// useful when you have tuple struct
|
||||
parameter_types.push(raw_param.clone());
|
||||
@ -129,8 +129,8 @@ pub(crate) fn from_enum_variant(db: &RootDatabase, variant: hir::EnumVariant) ->
|
||||
for field in variant.fields(db).into_iter() {
|
||||
let ty = field.signature_ty(db);
|
||||
let raw_param = format!("{}", ty.display(db));
|
||||
if let Some(param_type) = raw_param.split(':').nth(1) {
|
||||
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 {
|
||||
// The unwrap_or_else is useful when you have tuple
|
||||
parameter_types.push(raw_param);
|
||||
@ -197,7 +197,12 @@ fn param_list(node: &ast::FnDef) -> (bool, Vec<String>, Vec<String>) {
|
||||
let raw_param = self_param.syntax().text().to_string();
|
||||
|
||||
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);
|
||||
}
|
||||
@ -205,8 +210,8 @@ fn param_list(node: &ast::FnDef) -> (bool, Vec<String>, Vec<String>) {
|
||||
res.extend(param_list.params().map(|param| param.syntax().text().to_string()));
|
||||
res_types.extend(param_list.params().map(|param| {
|
||||
let param_text = param.syntax().text().to_string();
|
||||
match param_text.split(':').nth(1) {
|
||||
Some(it) => it[1..].to_string(),
|
||||
match param_text.split(':').nth(1).and_then(|it| it.get(1..)) {
|
||||
Some(it) => it.to_string(),
|
||||
None => param_text,
|
||||
}
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user