aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r--crates/ra_assists/src/ast_editor.rs2
-rw-r--r--crates/ra_assists/src/introduce_variable.rs9
2 files changed, 7 insertions, 4 deletions
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<ast::Block> {
274 274
275impl AstBuilder<ast::Expr> { 275impl AstBuilder<ast::Expr> {
276 fn from_text(text: &str) -> ast::Expr { 276 fn from_text(text: &str) -> ast::Expr {
277 ast_node_from_file_text(&format!("fn f() {{ {}; }}", text)) 277 ast_node_from_file_text(&format!("const C: () = {};", text))
278 } 278 }
279 279
280 pub fn unit() -> ast::Expr { 280 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;
3use ra_syntax::{ 3use ra_syntax::{
4 ast::{self, AstNode}, 4 ast::{self, AstNode},
5 SyntaxKind::{ 5 SyntaxKind::{
6 BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR, WHITESPACE, 6 BLOCK_EXPR, BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR,
7 WHITESPACE,
7 }, 8 },
8 SyntaxNode, TextUnit, 9 SyntaxNode, TextUnit,
9}; 10};
@@ -80,10 +81,12 @@ pub(crate) fn introduce_variable(mut ctx: AssistCtx<impl HirDatabase>) -> Option
80/// In general that's true for any expression, but in some cases that would produce invalid code. 81/// In general that's true for any expression, but in some cases that would produce invalid code.
81fn valid_target_expr(node: SyntaxNode) -> Option<ast::Expr> { 82fn valid_target_expr(node: SyntaxNode) -> Option<ast::Expr> {
82 match node.kind() { 83 match node.kind() {
83 PATH_EXPR => None, 84 PATH_EXPR | LOOP_EXPR => None,
84 BREAK_EXPR => ast::BreakExpr::cast(node).and_then(|e| e.expr()), 85 BREAK_EXPR => ast::BreakExpr::cast(node).and_then(|e| e.expr()),
85 RETURN_EXPR => ast::ReturnExpr::cast(node).and_then(|e| e.expr()), 86 RETURN_EXPR => ast::ReturnExpr::cast(node).and_then(|e| e.expr()),
86 LOOP_EXPR => ast::ReturnExpr::cast(node).and_then(|e| e.expr()), 87 BLOCK_EXPR => {
88 ast::BlockExpr::cast(node).filter(|it| it.is_standalone()).map(ast::Expr::from)
89 }
87 _ => ast::Expr::cast(node), 90 _ => ast::Expr::cast(node),
88 } 91 }
89} 92}