Skip to content

Commit eb3c235

Browse files
committed
Disable "Flip comma" assist inside a macro call
1 parent d5b8a40 commit eb3c235

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

crates/ide_assists/src/handlers/flip_comma.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use syntax::{algo::non_trivia_sibling, Direction, T};
1+
use syntax::{algo::non_trivia_sibling, Direction, SyntaxKind, T};
22

33
use crate::{AssistContext, AssistId, AssistKind, Assists};
44

@@ -28,6 +28,12 @@ pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
2828
return None;
2929
}
3030

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+
3137
acc.add(
3238
AssistId("flip_comma", AssistKind::RefactorRewrite),
3339
"Flip comma",
@@ -43,7 +49,7 @@ pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
4349
mod tests {
4450
use super::*;
4551

46-
use crate::tests::{check_assist, check_assist_target};
52+
use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target};
4753

4854
#[test]
4955
fn flip_comma_works_for_function_parameters() {
@@ -81,4 +87,20 @@ mod tests {
8187
",",
8288
);
8389
}
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+
}
84106
}

0 commit comments

Comments
 (0)