aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/move_item.rs96
1 files changed, 95 insertions, 1 deletions
diff --git a/crates/ide/src/move_item.rs b/crates/ide/src/move_item.rs
index de4e57b6a..806fd58da 100644
--- a/crates/ide/src/move_item.rs
+++ b/crates/ide/src/move_item.rs
@@ -43,6 +43,10 @@ fn find_ancestors(item: SyntaxElement, direction: Direction, range: TextRange) -
43 43
44 let movable = [ 44 let movable = [
45 SyntaxKind::ARG_LIST, 45 SyntaxKind::ARG_LIST,
46 SyntaxKind::GENERIC_PARAM_LIST,
47 SyntaxKind::GENERIC_ARG_LIST,
48 SyntaxKind::VARIANT_LIST,
49 SyntaxKind::TYPE_BOUND_LIST,
46 SyntaxKind::MATCH_ARM, 50 SyntaxKind::MATCH_ARM,
47 SyntaxKind::PARAM, 51 SyntaxKind::PARAM,
48 SyntaxKind::LET_STMT, 52 SyntaxKind::LET_STMT,
@@ -79,6 +83,10 @@ fn move_in_direction(
79 match_ast! { 83 match_ast! {
80 match node { 84 match node {
81 ast::ArgList(it) => swap_sibling_in_list(it.args(), range, direction), 85 ast::ArgList(it) => swap_sibling_in_list(it.args(), range, direction),
86 ast::GenericParamList(it) => swap_sibling_in_list(it.generic_params(), range, direction),
87 ast::GenericArgList(it) => swap_sibling_in_list(it.generic_args(), range, direction),
88 ast::VariantList(it) => swap_sibling_in_list(it.variants(), range, direction),
89 ast::TypeBoundList(it) => swap_sibling_in_list(it.bounds(), range, direction),
82 _ => Some(replace_nodes(node, &match direction { 90 _ => Some(replace_nodes(node, &match direction {
83 Direction::Up => node.prev_sibling(), 91 Direction::Up => node.prev_sibling(),
84 Direction::Down => node.next_sibling(), 92 Direction::Down => node.next_sibling(),
@@ -302,7 +310,7 @@ struct Yay;
302 310
303trait Wow {} 311trait Wow {}
304 312
305impl Wow for Yay {}$0$0 313impl Wow for Yay $0$0{}
306 "#, 314 "#,
307 expect![[r#" 315 expect![[r#"
308struct Yay; 316struct Yay;
@@ -442,6 +450,92 @@ fn main() {
442 } 450 }
443 451
444 #[test] 452 #[test]
453 fn test_moves_generic_param_up() {
454 check(
455 r#"
456struct Test<A, B$0$0>(A, B);
457
458fn main() {}
459 "#,
460 expect![[r#"
461struct Test<B, A>(A, B);
462
463fn main() {}
464 "#]],
465 Direction::Up,
466 );
467 }
468
469 #[test]
470 fn test_moves_generic_arg_up() {
471 check(
472 r#"
473struct Test<A, B>(A, B);
474
475fn main() {
476 let t = Test::<i32, &str$0$0>(123, "yay");
477}
478 "#,
479 expect![[r#"
480struct Test<A, B>(A, B);
481
482fn main() {
483 let t = Test::<&str, i32>(123, "yay");
484}
485 "#]],
486 Direction::Up,
487 );
488 }
489
490 #[test]
491 fn test_moves_variant_up() {
492 check(
493 r#"
494enum Hello {
495 One,
496 Two$0$0
497}
498
499fn main() {}
500 "#,
501 expect![[r#"
502enum Hello {
503 Two,
504 One
505}
506
507fn main() {}
508 "#]],
509 Direction::Up,
510 );
511 }
512
513 #[test]
514 fn test_moves_type_bound_up() {
515 check(
516 r#"
517trait One {}
518
519trait Two {}
520
521fn test<T: One + Two$0$0>(t: T) {}
522
523fn main() {}
524 "#,
525 expect![[r#"
526trait One {}
527
528trait Two {}
529
530fn test<T: Two + One>(t: T) {}
531
532fn main() {}
533 "#]],
534 Direction::Up,
535 );
536 }
537
538 #[test]
445 fn test_prioritizes_trait_items() { 539 fn test_prioritizes_trait_items() {
446 check( 540 check(
447 r#" 541 r#"