@@ -283,13 +283,17 @@ fn peel_parens(mut expr: ast::Expr) -> ast::Expr {
283283/// Check whether the node is a valid expression which can be extracted to a variable.
284284/// In general that's true for any expression, but in some cases that would produce invalid code.
285285fn valid_target_expr ( ctx : & AssistContext < ' _ > ) -> impl Fn ( SyntaxNode ) -> Option < ast:: Expr > {
286- |node| match node. kind ( ) {
286+ let selection = ctx. selection_trimmed ( ) ;
287+ move |node| match node. kind ( ) {
287288 SyntaxKind :: LOOP_EXPR | SyntaxKind :: LET_EXPR => None ,
288289 SyntaxKind :: BREAK_EXPR => ast:: BreakExpr :: cast ( node) . and_then ( |e| e. expr ( ) ) ,
289290 SyntaxKind :: RETURN_EXPR => ast:: ReturnExpr :: cast ( node) . and_then ( |e| e. expr ( ) ) ,
290291 SyntaxKind :: BLOCK_EXPR => {
291292 ast:: BlockExpr :: cast ( node) . filter ( |it| it. is_standalone ( ) ) . map ( ast:: Expr :: from)
292293 }
294+ SyntaxKind :: ARG_LIST => ast:: ArgList :: cast ( node) ?
295+ . args ( )
296+ . find ( |expr| crate :: utils:: is_selected ( expr, selection, false ) ) ,
293297 SyntaxKind :: PATH_EXPR => {
294298 let path_expr = ast:: PathExpr :: cast ( node) ?;
295299 let path_resolution = ctx. sema . resolve_path ( & path_expr. path ( ) ?) ?;
@@ -1285,6 +1289,33 @@ fn main() {
12851289 ) ;
12861290 }
12871291
1292+ #[ test]
1293+ fn extract_var_in_arglist_with_comma ( ) {
1294+ check_assist_by_label (
1295+ extract_variable,
1296+ r#"
1297+ fn main() {
1298+ let x = 2;
1299+ foo(
1300+ x + x,
1301+ $0x - x,$0
1302+ )
1303+ }
1304+ "# ,
1305+ r#"
1306+ fn main() {
1307+ let x = 2;
1308+ let $0var_name = x - x;
1309+ foo(
1310+ x + x,
1311+ var_name,
1312+ )
1313+ }
1314+ "# ,
1315+ "Extract into variable" ,
1316+ ) ;
1317+ }
1318+
12881319 #[ test]
12891320 fn extract_var_path_simple ( ) {
12901321 check_assist_by_label (
0 commit comments