diff options
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/join_lines.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs index 574ce219d..f5c310701 100644 --- a/crates/ra_ide/src/join_lines.rs +++ b/crates/ra_ide/src/join_lines.rs | |||
@@ -1,11 +1,10 @@ | |||
1 | use itertools::Itertools; | 1 | use itertools::Itertools; |
2 | use ra_assists::utils::extract_trivial_expression; | 2 | use ra_assists::utils::extract_trivial_expression; |
3 | use ra_fmt::compute_ws; | ||
4 | use syntax::{ | 3 | use syntax::{ |
5 | algo::{find_covering_element, non_trivia_sibling}, | 4 | algo::{find_covering_element, non_trivia_sibling}, |
6 | ast::{self, AstNode, AstToken}, | 5 | ast::{self, AstNode, AstToken}, |
7 | Direction, NodeOrToken, SourceFile, | 6 | Direction, NodeOrToken, SourceFile, |
8 | SyntaxKind::{self, WHITESPACE}, | 7 | SyntaxKind::{self, USE_TREE, WHITESPACE}, |
9 | SyntaxNode, SyntaxToken, TextRange, TextSize, T, | 8 | SyntaxNode, SyntaxToken, TextRange, TextSize, T, |
10 | }; | 9 | }; |
11 | use text_edit::{TextEdit, TextEditBuilder}; | 10 | use text_edit::{TextEdit, TextEditBuilder}; |
@@ -169,6 +168,29 @@ fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool { | |||
169 | matches!((left, right), (T![,], T![')']) | (T![,], T![']'])) | 168 | matches!((left, right), (T![,], T![')']) | (T![,], T![']'])) |
170 | } | 169 | } |
171 | 170 | ||
171 | fn compute_ws(left: SyntaxKind, right: SyntaxKind) -> &'static str { | ||
172 | match left { | ||
173 | T!['('] | T!['['] => return "", | ||
174 | T!['{'] => { | ||
175 | if let USE_TREE = right { | ||
176 | return ""; | ||
177 | } | ||
178 | } | ||
179 | _ => (), | ||
180 | } | ||
181 | match right { | ||
182 | T![')'] | T![']'] => return "", | ||
183 | T!['}'] => { | ||
184 | if let USE_TREE = left { | ||
185 | return ""; | ||
186 | } | ||
187 | } | ||
188 | T![.] => return "", | ||
189 | _ => (), | ||
190 | } | ||
191 | " " | ||
192 | } | ||
193 | |||
172 | #[cfg(test)] | 194 | #[cfg(test)] |
173 | mod tests { | 195 | mod tests { |
174 | use syntax::SourceFile; | 196 | use syntax::SourceFile; |