7794: Disable "Flip comma" assist inside a macro call r=Veykril a=greenhat

Fix #7693 

Disables "Flip comma" assist if called inside a macro call.

Co-authored-by: Denys Zadorozhnyi <denys@zadorozhnyi.com>
This commit is contained in:
bors[bot] 2021-02-26 18:10:07 +00:00 committed by GitHub
commit 2a4076c14d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 @@ fn flip_comma_before_punct() {
",",
);
}
#[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)"#);
}
}