From f0a9128761e8dd42f0dd40610a1d8734a52f3d9c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 11:41:20 +0200 Subject: Minor --- crates/ra_ide/src/join_lines.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs index 35cec87f6..574ce219d 100644 --- a/crates/ra_ide/src/join_lines.rs +++ b/crates/ra_ide/src/join_lines.rs @@ -1,5 +1,6 @@ use itertools::Itertools; -use ra_fmt::{compute_ws, extract_trivial_expression}; +use ra_assists::utils::extract_trivial_expression; +use ra_fmt::compute_ws; use syntax::{ algo::{find_covering_element, non_trivia_sibling}, ast::{self, AstNode, AstToken}, -- cgit v1.2.3 From 80c241b39a02a949c745676e22b28db95186feda Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 11:44:39 +0200 Subject: Minor --- crates/ra_ide/src/join_lines.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src') 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 @@ use itertools::Itertools; use ra_assists::utils::extract_trivial_expression; -use ra_fmt::compute_ws; use syntax::{ algo::{find_covering_element, non_trivia_sibling}, ast::{self, AstNode, AstToken}, Direction, NodeOrToken, SourceFile, - SyntaxKind::{self, WHITESPACE}, + SyntaxKind::{self, USE_TREE, WHITESPACE}, SyntaxNode, SyntaxToken, TextRange, TextSize, T, }; use text_edit::{TextEdit, TextEditBuilder}; @@ -169,6 +168,29 @@ fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool { matches!((left, right), (T![,], T![')']) | (T![,], T![']'])) } +fn compute_ws(left: SyntaxKind, right: SyntaxKind) -> &'static str { + match left { + T!['('] | T!['['] => return "", + T!['{'] => { + if let USE_TREE = right { + return ""; + } + } + _ => (), + } + match right { + T![')'] | T![']'] => return "", + T!['}'] => { + if let USE_TREE = left { + return ""; + } + } + T![.] => return "", + _ => (), + } + " " +} + #[cfg(test)] mod tests { use syntax::SourceFile; -- cgit v1.2.3