aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/join_lines.rs
diff options
context:
space:
mode:
authorSergey Parilin <[email protected]>2019-05-15 13:35:47 +0100
committerSergey Parilin <[email protected]>2019-05-15 13:35:47 +0100
commit993abedd77cf23ce2281b6c8e60cab49ab4fa97e (patch)
treeb8693ce808a9ca2e7eaae5013644a1082fc7bb17 /crates/ra_ide_api/src/join_lines.rs
parentd77175ce28da45960a89811f273b6c614d7a9413 (diff)
apply T! macro where it is possible
Diffstat (limited to 'crates/ra_ide_api/src/join_lines.rs')
-rw-r--r--crates/ra_ide_api/src/join_lines.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/crates/ra_ide_api/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs
index 598717311..4ca005466 100644
--- a/crates/ra_ide_api/src/join_lines.rs
+++ b/crates/ra_ide_api/src/join_lines.rs
@@ -1,7 +1,8 @@
1use itertools::Itertools; 1use itertools::Itertools;
2use ra_syntax::{ 2use ra_syntax::{
3 T,
3 SourceFile, TextRange, TextUnit, SyntaxNode, SyntaxElement, SyntaxToken, 4 SourceFile, TextRange, TextUnit, SyntaxNode, SyntaxElement, SyntaxToken,
4 SyntaxKind::{self, WHITESPACE, COMMA, R_CURLY, R_PAREN, R_BRACK}, 5 SyntaxKind::{self, WHITESPACE},
5 algo::{find_covering_element, non_trivia_sibling}, 6 algo::{find_covering_element, non_trivia_sibling},
6 ast::{self, AstNode, AstToken}, 7 ast::{self, AstNode, AstToken},
7 Direction, 8 Direction,
@@ -89,7 +90,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: SyntaxToken, offset: TextUn
89 if is_trailing_comma(prev.kind(), next.kind()) { 90 if is_trailing_comma(prev.kind(), next.kind()) {
90 // Removes: trailing comma, newline (incl. surrounding whitespace) 91 // Removes: trailing comma, newline (incl. surrounding whitespace)
91 edit.delete(TextRange::from_to(prev.range().start(), token.range().end())); 92 edit.delete(TextRange::from_to(prev.range().start(), token.range().end()));
92 } else if prev.kind() == COMMA && next.kind() == R_CURLY { 93 } else if prev.kind() == T![,] && next.kind() == T!['}'] {
93 // Removes: comma, newline (incl. surrounding whitespace) 94 // Removes: comma, newline (incl. surrounding whitespace)
94 let space = if let Some(left) = prev.prev_sibling_or_token() { 95 let space = if let Some(left) = prev.prev_sibling_or_token() {
95 compute_ws(left.kind(), next.kind()) 96 compute_ws(left.kind(), next.kind())
@@ -116,7 +117,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: SyntaxToken, offset: TextUn
116 117
117fn has_comma_after(node: &SyntaxNode) -> bool { 118fn has_comma_after(node: &SyntaxNode) -> bool {
118 match non_trivia_sibling(node.into(), Direction::Next) { 119 match non_trivia_sibling(node.into(), Direction::Next) {
119 Some(n) => n.kind() == COMMA, 120 Some(n) => n.kind() == T![,],
120 _ => false, 121 _ => false,
121 } 122 }
122} 123}
@@ -150,7 +151,7 @@ fn join_single_use_tree(edit: &mut TextEditBuilder, token: SyntaxToken) -> Optio
150 151
151fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool { 152fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool {
152 match (left, right) { 153 match (left, right) {
153 (COMMA, R_PAREN) | (COMMA, R_BRACK) => true, 154 (T![,], T![')']) | (T![,], T![']']) => true,
154 _ => false, 155 _ => false,
155 } 156 }
156} 157}