Skip to content

Commit

Permalink
Deunwrap inline call v2
Browse files Browse the repository at this point in the history
  • Loading branch information
alibektas committed Sep 9, 2023
1 parent aa6344f commit 94afbe3
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions crates/ide-assists/src/handlers/inline_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext<'_>) ->
.map(|(call_info, mut_node)| {
let replacement =
inline(&ctx.sema, def_file, function, &func_body, &params, &call_info)
.unwrap();
.expect("inline() should return an Expr");
ted::replace(mut_node, replacement.syntax());
})
.count();
Expand Down Expand Up @@ -363,17 +363,23 @@ fn inline(
.collect();

if function.self_param(sema.db).is_some() {
let this = || make::name_ref("this").syntax().clone_for_update().first_token();
let this = || {
make::name_ref("this")
.syntax()
.clone_for_update()
.first_token()
.expect("NameRef should have had a token.")
};
if let Some(self_local) = params[0].2.as_local(sema.db) {
let usages = usages_for_locals(self_local).filter_map(
|FileReference { name, range, .. }| match name {
usages_for_locals(self_local)
.filter_map(|FileReference { name, range, .. }| match name {
ast::NameLike::NameRef(_) => Some(body.syntax().covering_element(range)),
_ => None,
},
);
for usage in usages {
ted::replace(usage, &this()?);
}
})
.into_iter()
.for_each(|usage| {
ted::replace(usage, &this());
});
}
}

Expand Down Expand Up @@ -471,7 +477,9 @@ fn inline(
}
} else if let Some(stmt_list) = body.stmt_list() {
ted::insert_all(
ted::Position::after(stmt_list.l_curly_token()?),
ted::Position::after(
stmt_list.l_curly_token().expect("L_CURLY for StatementList is missing."),
),
let_stmts.into_iter().map(|stmt| stmt.syntax().clone().into()).collect(),
);
}
Expand Down

0 comments on commit 94afbe3

Please sign in to comment.