aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_fmt/src/lib.rs27
-rw-r--r--crates/ra_ide/src/join_lines.rs26
2 files changed, 25 insertions, 28 deletions
diff --git a/crates/ra_fmt/src/lib.rs b/crates/ra_fmt/src/lib.rs
index d0004654b..b92477f9e 100644
--- a/crates/ra_fmt/src/lib.rs
+++ b/crates/ra_fmt/src/lib.rs
@@ -4,9 +4,7 @@ use std::iter::successors;
4 4
5use syntax::{ 5use syntax::{
6 ast::{self, AstToken}, 6 ast::{self, AstToken},
7 SmolStr, SyntaxKind, 7 SmolStr, SyntaxNode, SyntaxToken,
8 SyntaxKind::*,
9 SyntaxNode, SyntaxToken, T,
10}; 8};
11 9
12/// If the node is on the beginning of the line, calculate indent. 10/// If the node is on the beginning of the line, calculate indent.
@@ -28,26 +26,3 @@ pub fn leading_indent(node: &SyntaxNode) -> Option<SmolStr> {
28fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> { 26fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> {
29 successors(token.prev_token(), |token| token.prev_token()) 27 successors(token.prev_token(), |token| token.prev_token())
30} 28}
31
32pub fn compute_ws(left: SyntaxKind, right: SyntaxKind) -> &'static str {
33 match left {
34 T!['('] | T!['['] => return "",
35 T!['{'] => {
36 if let USE_TREE = right {
37 return "";
38 }
39 }
40 _ => (),
41 }
42 match right {
43 T![')'] | T![']'] => return "",
44 T!['}'] => {
45 if let USE_TREE = left {
46 return "";
47 }
48 }
49 T![.] => return "",
50 _ => (),
51 }
52 " "
53}
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 @@
1use itertools::Itertools; 1use itertools::Itertools;
2use ra_assists::utils::extract_trivial_expression; 2use ra_assists::utils::extract_trivial_expression;
3use ra_fmt::compute_ws;
4use syntax::{ 3use 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};
11use text_edit::{TextEdit, TextEditBuilder}; 10use 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
171fn 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)]
173mod tests { 195mod tests {
174 use syntax::SourceFile; 196 use syntax::SourceFile;