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_fmt/src/lib.rs | 27 +-------------------------- crates/ra_ide/src/join_lines.rs | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 28 deletions(-) (limited to 'crates') 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; use syntax::{ ast::{self, AstToken}, - SmolStr, SyntaxKind, - SyntaxKind::*, - SyntaxNode, SyntaxToken, T, + SmolStr, SyntaxNode, SyntaxToken, }; /// If the node is on the beginning of the line, calculate indent. @@ -28,26 +26,3 @@ pub fn leading_indent(node: &SyntaxNode) -> Option { fn prev_tokens(token: SyntaxToken) -> impl Iterator { successors(token.prev_token(), |token| token.prev_token()) } - -pub 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 "", - _ => (), - } - " " -} 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