diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-02-26 18:10:07 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-02-26 18:10:07 +0000 |
commit | 2a4076c14d0e3f7ae03908c2b9cd1a52851d401c (patch) | |
tree | da8ac119f7c6caee49fda4bcd2cdb593e9f2b22b /crates/ide_assists/src/handlers/flip_comma.rs | |
parent | d5b8a401f38f88ecb0d894c88dcbab3d338a0ef2 (diff) | |
parent | eb3c23588df888454b943bb6feb82a7e97ce1a9b (diff) |
Merge #7794
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 <[email protected]>
Diffstat (limited to 'crates/ide_assists/src/handlers/flip_comma.rs')
-rw-r--r-- | crates/ide_assists/src/handlers/flip_comma.rs | 26 |
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 @@ | |||
1 | use syntax::{algo::non_trivia_sibling, Direction, T}; | 1 | use syntax::{algo::non_trivia_sibling, Direction, SyntaxKind, T}; |
2 | 2 | ||
3 | use crate::{AssistContext, AssistId, AssistKind, Assists}; | 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 | 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<()> { | |||
43 | mod tests { | 49 | mod 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 | } |