From eb3c23588df888454b943bb6feb82a7e97ce1a9b Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Fri, 26 Feb 2021 19:12:53 +0200 Subject: Disable "Flip comma" assist inside a macro call --- crates/ide_assists/src/handlers/flip_comma.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'crates') 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 @@ -use syntax::{algo::non_trivia_sibling, Direction, T}; +use syntax::{algo::non_trivia_sibling, Direction, SyntaxKind, T}; use crate::{AssistContext, AssistId, AssistKind, Assists}; @@ -28,6 +28,12 @@ pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { return None; } + // Don't apply a "flip" inside the macro call + // since macro input are just mere tokens + if comma.ancestors().any(|it| it.kind() == SyntaxKind::MACRO_CALL) { + return None; + } + acc.add( AssistId("flip_comma", AssistKind::RefactorRewrite), "Flip comma", @@ -43,7 +49,7 @@ pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { mod tests { use super::*; - use crate::tests::{check_assist, check_assist_target}; + use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; #[test] fn flip_comma_works_for_function_parameters() { @@ -81,4 +87,20 @@ mod tests { ",", ); } + + #[test] + fn flip_comma_works() { + check_assist( + flip_comma, + r#"fn main() {((1, 2),$0 (3, 4));}"#, + r#"fn main() {((3, 4), (1, 2));}"#, + ) + } + + #[test] + fn flip_comma_not_applicable_for_macro_input() { + // "Flip comma" assist shouldn't be applicable inside the macro call + // See https://github.com/rust-analyzer/rust-analyzer/issues/7693 + check_assist_not_applicable(flip_comma, r#"bar!(a,$0 b)"#); + } } -- cgit v1.2.3