1
- use syntax:: { algo:: non_trivia_sibling, Direction , T } ;
1
+ use syntax:: { algo:: non_trivia_sibling, Direction , SyntaxKind , T } ;
2
2
3
3
use crate :: { AssistContext , AssistId , AssistKind , Assists } ;
4
4
@@ -28,6 +28,12 @@ pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
28
28
return None ;
29
29
}
30
30
31
+ // Don't apply a "flip" inside the macro call
32
+ // since macro input are just mere tokens
33
+ if comma. ancestors ( ) . any ( |it| it. kind ( ) == SyntaxKind :: MACRO_CALL ) {
34
+ return None ;
35
+ }
36
+
31
37
acc. add (
32
38
AssistId ( "flip_comma" , AssistKind :: RefactorRewrite ) ,
33
39
"Flip comma" ,
@@ -43,7 +49,7 @@ pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
43
49
mod tests {
44
50
use super :: * ;
45
51
46
- use crate :: tests:: { check_assist, check_assist_target} ;
52
+ use crate :: tests:: { check_assist, check_assist_not_applicable , check_assist_target} ;
47
53
48
54
#[ test]
49
55
fn flip_comma_works_for_function_parameters ( ) {
@@ -81,4 +87,20 @@ mod tests {
81
87
"," ,
82
88
) ;
83
89
}
90
+
91
+ #[ test]
92
+ fn flip_comma_works ( ) {
93
+ check_assist (
94
+ flip_comma,
95
+ r#"fn main() {((1, 2),$0 (3, 4));}"# ,
96
+ r#"fn main() {((3, 4), (1, 2));}"# ,
97
+ )
98
+ }
99
+
100
+ #[ test]
101
+ fn flip_comma_not_applicable_for_macro_input ( ) {
102
+ // "Flip comma" assist shouldn't be applicable inside the macro call
103
+ // See https://github.com/rust-analyzer/rust-analyzer/issues/7693
104
+ check_assist_not_applicable ( flip_comma, r#"bar!(a,$0 b)"# ) ;
105
+ }
84
106
}
0 commit comments