diff options
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/move_item.rs | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/crates/ide/src/move_item.rs b/crates/ide/src/move_item.rs index be62d008d..5a0faaf7b 100644 --- a/crates/ide/src/move_item.rs +++ b/crates/ide/src/move_item.rs | |||
@@ -33,26 +33,6 @@ pub(crate) fn move_item( | |||
33 | } | 33 | } |
34 | 34 | ||
35 | fn find_ancestors(item: SyntaxElement, direction: Direction) -> Option<TextEdit> { | 35 | fn find_ancestors(item: SyntaxElement, direction: Direction) -> Option<TextEdit> { |
36 | let movable = [ | ||
37 | SyntaxKind::MATCH_ARM, | ||
38 | // https://github.com/intellij-rust/intellij-rust/blob/master/src/main/kotlin/org/rust/ide/actions/mover/RsStatementUpDownMover.kt | ||
39 | SyntaxKind::LET_STMT, | ||
40 | SyntaxKind::EXPR_STMT, | ||
41 | SyntaxKind::MATCH_EXPR, | ||
42 | // https://github.com/intellij-rust/intellij-rust/blob/master/src/main/kotlin/org/rust/ide/actions/mover/RsItemUpDownMover.kt | ||
43 | SyntaxKind::TRAIT, | ||
44 | SyntaxKind::IMPL, | ||
45 | SyntaxKind::MACRO_CALL, | ||
46 | SyntaxKind::MACRO_DEF, | ||
47 | SyntaxKind::STRUCT, | ||
48 | SyntaxKind::ENUM, | ||
49 | SyntaxKind::MODULE, | ||
50 | SyntaxKind::USE, | ||
51 | SyntaxKind::FN, | ||
52 | SyntaxKind::CONST, | ||
53 | SyntaxKind::TYPE_ALIAS, | ||
54 | ]; | ||
55 | |||
56 | let root = match item { | 36 | let root = match item { |
57 | NodeOrToken::Node(node) => node, | 37 | NodeOrToken::Node(node) => node, |
58 | NodeOrToken::Token(token) => token.parent(), | 38 | NodeOrToken::Token(token) => token.parent(), |
@@ -60,17 +40,18 @@ fn find_ancestors(item: SyntaxElement, direction: Direction) -> Option<TextEdit> | |||
60 | 40 | ||
61 | let ancestor = once(root.clone()) | 41 | let ancestor = once(root.clone()) |
62 | .chain(root.ancestors()) | 42 | .chain(root.ancestors()) |
63 | .filter(|ancestor| movable.contains(&ancestor.kind())) | 43 | .filter_map(|ancestor| kind_priority(ancestor.kind()).map(|priority| (priority, ancestor))) |
64 | .max_by_key(|ancestor| kind_priority(ancestor.kind()))?; | 44 | .max_by_key(|(priority, _)| *priority) |
45 | .map(|(_, ancestor)| ancestor)?; | ||
65 | 46 | ||
66 | move_in_direction(&ancestor, direction) | 47 | move_in_direction(&ancestor, direction) |
67 | } | 48 | } |
68 | 49 | ||
69 | fn kind_priority(kind: SyntaxKind) -> i32 { | 50 | fn kind_priority(kind: SyntaxKind) -> Option<i32> { |
70 | match kind { | 51 | match kind { |
71 | SyntaxKind::MATCH_ARM => 4, | 52 | SyntaxKind::MATCH_ARM => Some(4), |
72 | 53 | ||
73 | SyntaxKind::LET_STMT | SyntaxKind::EXPR_STMT | SyntaxKind::MATCH_EXPR => 3, | 54 | SyntaxKind::LET_STMT | SyntaxKind::EXPR_STMT | SyntaxKind::MATCH_EXPR => Some(3), |
74 | 55 | ||
75 | SyntaxKind::TRAIT | 56 | SyntaxKind::TRAIT |
76 | | SyntaxKind::IMPL | 57 | | SyntaxKind::IMPL |
@@ -82,10 +63,9 @@ fn kind_priority(kind: SyntaxKind) -> i32 { | |||
82 | | SyntaxKind::USE | 63 | | SyntaxKind::USE |
83 | | SyntaxKind::FN | 64 | | SyntaxKind::FN |
84 | | SyntaxKind::CONST | 65 | | SyntaxKind::CONST |
85 | | SyntaxKind::TYPE_ALIAS => 2, | 66 | | SyntaxKind::TYPE_ALIAS => Some(2), |
86 | 67 | ||
87 | // Placeholder for items, that are non-movable, and filtered even before kind_priority call | 68 | _ => None, |
88 | _ => 1, | ||
89 | } | 69 | } |
90 | } | 70 | } |
91 | 71 | ||