From e94587e3153b52684fd3f6b82c8e7efc09ff5c8d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 2 Sep 2019 21:41:50 +0300 Subject: fix assists --- crates/ra_assists/src/ast_editor.rs | 2 +- crates/ra_assists/src/introduce_variable.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs index 6815638dc..048478662 100644 --- a/crates/ra_assists/src/ast_editor.rs +++ b/crates/ra_assists/src/ast_editor.rs @@ -274,7 +274,7 @@ impl AstBuilder { impl AstBuilder { fn from_text(text: &str) -> ast::Expr { - ast_node_from_file_text(&format!("fn f() {{ {}; }}", text)) + ast_node_from_file_text(&format!("const C: () = {};", text)) } pub fn unit() -> ast::Expr { diff --git a/crates/ra_assists/src/introduce_variable.rs b/crates/ra_assists/src/introduce_variable.rs index 95c18d0e3..470ffe120 100644 --- a/crates/ra_assists/src/introduce_variable.rs +++ b/crates/ra_assists/src/introduce_variable.rs @@ -3,7 +3,8 @@ use hir::db::HirDatabase; use ra_syntax::{ ast::{self, AstNode}, SyntaxKind::{ - BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR, WHITESPACE, + BLOCK_EXPR, BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR, + WHITESPACE, }, SyntaxNode, TextUnit, }; @@ -80,10 +81,12 @@ pub(crate) fn introduce_variable(mut ctx: AssistCtx) -> Option /// In general that's true for any expression, but in some cases that would produce invalid code. fn valid_target_expr(node: SyntaxNode) -> Option { match node.kind() { - PATH_EXPR => None, + PATH_EXPR | LOOP_EXPR => None, BREAK_EXPR => ast::BreakExpr::cast(node).and_then(|e| e.expr()), RETURN_EXPR => ast::ReturnExpr::cast(node).and_then(|e| e.expr()), - LOOP_EXPR => ast::ReturnExpr::cast(node).and_then(|e| e.expr()), + BLOCK_EXPR => { + ast::BlockExpr::cast(node).filter(|it| it.is_standalone()).map(ast::Expr::from) + } _ => ast::Expr::cast(node), } } -- cgit v1.2.3