aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_assists/src/handlers')
-rw-r--r--crates/ide_assists/src/handlers/flip_comma.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/crates/ide_assists/src/handlers/flip_comma.rs b/crates/ide_assists/src/handlers/flip_comma.rs
index 18cf64a34..7f5e75d34 100644
--- a/crates/ide_assists/src/handlers/flip_comma.rs
+++ b/crates/ide_assists/src/handlers/flip_comma.rs
@@ -1,4 +1,4 @@
1use syntax::{algo::non_trivia_sibling, Direction, T}; 1use syntax::{algo::non_trivia_sibling, Direction, SyntaxKind, T};
2 2
3use crate::{AssistContext, AssistId, AssistKind, Assists}; 3use crate::{AssistContext, AssistId, AssistKind, Assists};
4 4
@@ -28,6 +28,12 @@ pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
28 return None; 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 acc.add( 37 acc.add(
32 AssistId("flip_comma", AssistKind::RefactorRewrite), 38 AssistId("flip_comma", AssistKind::RefactorRewrite),
33 "Flip comma", 39 "Flip comma",
@@ -43,7 +49,7 @@ pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
43mod tests { 49mod tests {
44 use super::*; 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 #[test] 54 #[test]
49 fn flip_comma_works_for_function_parameters() { 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}