Deunwrap wrap_return_type_in_result
This commit is contained in:
parent
b78d69c795
commit
a46eebbc9f
@ -48,6 +48,12 @@ pub(crate) fn wrap_return_type_in_result(acc: &mut Assists, ctx: &AssistContext<
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let new_result_ty =
|
||||||
|
make::ext::ty_result(type_ref.clone(), make::ty_placeholder()).clone_for_update();
|
||||||
|
let generic_args =
|
||||||
|
new_result_ty.syntax().descendants().find_map(ast::GenericArgList::cast).unwrap();
|
||||||
|
let last_genarg = generic_args.generic_args().last()?;
|
||||||
|
|
||||||
acc.add(
|
acc.add(
|
||||||
AssistId("wrap_return_type_in_result", AssistKind::RefactorRewrite),
|
AssistId("wrap_return_type_in_result", AssistKind::RefactorRewrite),
|
||||||
"Wrap return type in Result",
|
"Wrap return type in Result",
|
||||||
@ -75,19 +81,12 @@ pub(crate) fn wrap_return_type_in_result(acc: &mut Assists, ctx: &AssistContext<
|
|||||||
ted::replace(ret_expr_arg.syntax(), ok_wrapped.syntax());
|
ted::replace(ret_expr_arg.syntax(), ok_wrapped.syntax());
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_result_ty =
|
|
||||||
make::ext::ty_result(type_ref.clone(), make::ty_placeholder()).clone_for_update();
|
|
||||||
let old_result_ty = edit.make_mut(type_ref.clone());
|
let old_result_ty = edit.make_mut(type_ref.clone());
|
||||||
|
|
||||||
ted::replace(old_result_ty.syntax(), new_result_ty.syntax());
|
ted::replace(old_result_ty.syntax(), new_result_ty.syntax());
|
||||||
|
|
||||||
if let Some(cap) = ctx.config.snippet_cap {
|
if let Some(cap) = ctx.config.snippet_cap {
|
||||||
let generic_args = new_result_ty
|
edit.add_placeholder_snippet(cap, last_genarg);
|
||||||
.syntax()
|
|
||||||
.descendants()
|
|
||||||
.find_map(ast::GenericArgList::cast)
|
|
||||||
.unwrap();
|
|
||||||
edit.add_placeholder_snippet(cap, generic_args.generic_args().last().unwrap());
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user