use has_semi

This commit is contained in:
Yerkebulan Tulibergenov 2019-01-15 20:27:15 -08:00
parent 5e35f191fc
commit 4dd7ec94bc

View File

@ -20,16 +20,15 @@ pub fn introduce_variable<'a>(ctx: AssistCtx) -> Option<Assist> {
buf.push_str("let var_name = ");
expr.syntax().text().push_to(&mut buf);
let is_full_stmt = if let Some(expr_stmt) = ast::ExprStmt::cast(anchor_stmt) {
let full_stmt = ast::ExprStmt::cast(anchor_stmt);
let is_full_stmt = if let Some(expr_stmt) = full_stmt {
Some(expr.syntax()) == expr_stmt.expr().map(|e| e.syntax())
} else {
false
};
if is_full_stmt {
if let Some(last_child) = expr.syntax().last_child() {
if last_child.kind() != SEMI && !is_semi_right_after(expr.syntax()) {
buf.push_str(";");
}
if !full_stmt.unwrap().has_semi() {
buf.push_str(";");
}
edit.replace(expr.syntax().range(), buf);
} else {