1
- use crate :: { Assist , AssistCtx , AssistId , TextRange , TextUnit } ;
2
1
use hir:: db:: HirDatabase ;
3
- use ra_syntax:: ast:: { AstNode , MatchArm } ;
2
+ use ra_syntax:: ast:: { self , AstNode } ;
3
+
4
+ use crate :: { Assist , AssistCtx , AssistId , TextRange , TextUnit } ;
4
5
5
6
// Assist: merge_match_arms
6
7
//
@@ -27,12 +28,12 @@ use ra_syntax::ast::{AstNode, MatchArm};
27
28
// }
28
29
// ```
29
30
pub ( crate ) fn merge_match_arms ( ctx : AssistCtx < impl HirDatabase > ) -> Option < Assist > {
30
- let current_arm = ctx. find_node_at_offset :: < MatchArm > ( ) ?;
31
+ let current_arm = ctx. find_node_at_offset :: < ast :: MatchArm > ( ) ?;
31
32
32
33
// We check if the following match arm matches this one. We could, but don't,
33
34
// compare to the previous match arm as well.
34
35
let next = current_arm. syntax ( ) . next_sibling ( ) ;
35
- let next_arm = MatchArm :: cast ( next?) ?;
36
+ let next_arm = ast :: MatchArm :: cast ( next?) ?;
36
37
37
38
// Don't try to handle arms with guards for now - can add support for this later
38
39
if current_arm. guard ( ) . is_some ( ) || next_arm. guard ( ) . is_some ( ) {
@@ -53,13 +54,6 @@ pub(crate) fn merge_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assis
53
54
let cursor_to_end = current_arm. syntax ( ) . text_range ( ) . end ( ) - ctx. frange . range . start ( ) ;
54
55
55
56
ctx. add_assist ( AssistId ( "merge_match_arms" ) , "Merge match arms" , |edit| {
56
- fn contains_placeholder ( a : & MatchArm ) -> bool {
57
- a. pats ( ) . any ( |x| match x {
58
- ra_syntax:: ast:: Pat :: PlaceholderPat ( ..) => true ,
59
- _ => false ,
60
- } )
61
- }
62
-
63
57
let pats = if contains_placeholder ( & current_arm) || contains_placeholder ( & next_arm) {
64
58
"_" . into ( )
65
59
} else {
@@ -83,6 +77,13 @@ pub(crate) fn merge_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assis
83
77
} )
84
78
}
85
79
80
+ fn contains_placeholder ( a : & ast:: MatchArm ) -> bool {
81
+ a. pats ( ) . any ( |x| match x {
82
+ ra_syntax:: ast:: Pat :: PlaceholderPat ( ..) => true ,
83
+ _ => false ,
84
+ } )
85
+ }
86
+
86
87
#[ cfg( test) ]
87
88
mod tests {
88
89
use super :: merge_match_arms;
0 commit comments