diff --git a/crates/squawk_ide/src/code_actions.rs b/crates/squawk_ide/src/code_actions.rs index 2de3c04a..30cefb21 100644 --- a/crates/squawk_ide/src/code_actions.rs +++ b/crates/squawk_ide/src/code_actions.rs @@ -523,7 +523,9 @@ fn rewrite_double_colon_to_cast( let token = token_from_offset(file, offset)?; let cast_expr = token.parent_ancestors().find_map(ast::CastExpr::cast)?; - cast_expr.colon_colon()?; + if cast_expr.cast_token().is_some() { + return None; + } let expr = cast_expr.expr()?; let ty = cast_expr.ty()?; @@ -1626,6 +1628,24 @@ select myschema.f$0();" ); } + #[test] + fn rewrite_cast_to_double_colon_type_first_syntax() { + assert_snapshot!(apply_code_action( + rewrite_cast_to_double_colon, + "select in$0t '1';"), + @"select '1'::int;" + ); + } + + #[test] + fn rewrite_cast_to_double_colon_type_first_qualified() { + assert_snapshot!(apply_code_action( + rewrite_cast_to_double_colon, + "select pg_catalog.int$04 '1';"), + @"select '1'::pg_catalog.int4;" + ); + } + #[test] fn rewrite_cast_to_double_colon_not_applicable_already_double_colon() { assert!(code_action_not_applicable( @@ -1687,6 +1707,24 @@ select myschema.f$0();" ); } + #[test] + fn rewrite_type_literal_syntax_to_cast() { + assert_snapshot!(apply_code_action( + rewrite_double_colon_to_cast, + "select in$0t '1';"), + @"select cast('1' as int);" + ); + } + + #[test] + fn rewrite_qualified_type_literal_syntax_to_cast() { + assert_snapshot!(apply_code_action( + rewrite_double_colon_to_cast, + "select pg_catalog.int$04 '1';"), + @"select cast('1' as pg_catalog.int4);" + ); + } + #[test] fn rewrite_double_colon_to_cast_not_applicable_already_cast() { assert!(code_action_not_applicable(