aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/join_lines.rs69
1 files changed, 46 insertions, 23 deletions
diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs
index 7deeb3494..552d7f66e 100644
--- a/crates/ra_ide/src/join_lines.rs
+++ b/crates/ra_ide/src/join_lines.rs
@@ -60,29 +60,6 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU
60 return; 60 return;
61 } 61 }
62 62
63 // Special case that turns something like:
64 //
65 // ```
66 // my_function({<|>
67 // <some-expr>
68 // })
69 // ```
70 //
71 // into `my_function(<some-expr>)`
72 if join_single_expr_block(edit, token).is_some() {
73 return;
74 }
75 // ditto for
76 //
77 // ```
78 // use foo::{<|>
79 // bar
80 // };
81 // ```
82 if join_single_use_tree(edit, token).is_some() {
83 return;
84 }
85
86 // The node is between two other nodes 63 // The node is between two other nodes
87 let prev = token.prev_sibling_or_token().unwrap(); 64 let prev = token.prev_sibling_or_token().unwrap();
88 let next = token.next_sibling_or_token().unwrap(); 65 let next = token.next_sibling_or_token().unwrap();
@@ -110,6 +87,29 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU
110 next.syntax().text_range().start() + TextUnit::of_str(next.prefix()), 87 next.syntax().text_range().start() + TextUnit::of_str(next.prefix()),
111 )); 88 ));
112 } else { 89 } else {
90 // Special case that turns something like:
91 //
92 // ```
93 // my_function({<|>
94 // <some-expr>
95 // })
96 // ```
97 //
98 // into `my_function(<some-expr>)`
99 if join_single_expr_block(edit, token).is_some() {
100 return;
101 }
102 // ditto for
103 //
104 // ```
105 // use foo::{<|>
106 // bar
107 // };
108 // ```
109 if join_single_use_tree(edit, token).is_some() {
110 return;
111 }
112
113 // Remove newline but add a computed amount of whitespace characters 113 // Remove newline but add a computed amount of whitespace characters
114 edit.replace(token.text_range(), compute_ws(prev.kind(), next.kind()).to_string()); 114 edit.replace(token.text_range(), compute_ws(prev.kind(), next.kind()).to_string());
115 } 115 }
@@ -608,4 +608,27 @@ pub fn handle_find_matching_brace() {
608}", 608}",
609 ); 609 );
610 } 610 }
611
612 #[test]
613 fn test_join_lines_commented_block() {
614 check_join_lines(
615 r"
616fn main() {
617 let _ = {
618 // <|>foo
619 // bar
620 92
621 };
622}
623 ",
624 r"
625fn main() {
626 let _ = {
627 // <|>foo bar
628 92
629 };
630}
631 ",
632 )
633 }
611} 634}