From 993abedd77cf23ce2281b6c8e60cab49ab4fa97e Mon Sep 17 00:00:00 2001 From: Sergey Parilin Date: Wed, 15 May 2019 15:35:47 +0300 Subject: apply T! macro where it is possible --- crates/ra_ide_api/src/diagnostics.rs | 6 ++---- crates/ra_ide_api/src/extend_selection.rs | 2 +- crates/ra_ide_api/src/join_lines.rs | 9 +++++---- crates/ra_ide_api/src/matching_brace.rs | 5 +++-- crates/ra_ide_api/src/syntax_highlighting.rs | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index e23d178b0..9a0eb2c14 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs @@ -4,7 +4,7 @@ use itertools::Itertools; use hir::{source_binder, diagnostics::{Diagnostic as _, DiagnosticSink}}; use ra_db::SourceDatabase; use ra_syntax::{ - Location, SourceFile, SyntaxKind, TextRange, SyntaxNode, + T, Location, SourceFile, TextRange, SyntaxNode, ast::{self, AstNode, NamedFieldList, NamedField}, }; use ra_assists::ast_editor::{AstEditor, AstBuilder}; @@ -130,9 +130,7 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement( single_use_tree: &ast::UseTree, ) -> Option { let use_tree_list_node = single_use_tree.syntax().parent()?; - if single_use_tree.path()?.segment()?.syntax().first_child_or_token()?.kind() - == SyntaxKind::SELF_KW - { + if single_use_tree.path()?.segment()?.syntax().first_child_or_token()?.kind() == T![self] { let start = use_tree_list_node.prev_sibling_or_token()?.range().start(); let end = use_tree_list_node.range().end(); let range = TextRange::from_to(start, end); diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index 163fa8c3c..4553faad0 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs @@ -157,7 +157,7 @@ fn extend_list_item(node: &SyntaxNode) -> Option { }) .next() .and_then(|it| it.as_token()) - .filter(|node| node.kind() == COMMA) + .filter(|node| node.kind() == T![,]) } if let Some(comma_node) = nearby_comma(node, Direction::Prev) { 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 @@ use itertools::Itertools; use ra_syntax::{ + T, SourceFile, TextRange, TextUnit, SyntaxNode, SyntaxElement, SyntaxToken, - SyntaxKind::{self, WHITESPACE, COMMA, R_CURLY, R_PAREN, R_BRACK}, + SyntaxKind::{self, WHITESPACE}, algo::{find_covering_element, non_trivia_sibling}, ast::{self, AstNode, AstToken}, Direction, @@ -89,7 +90,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: SyntaxToken, offset: TextUn if is_trailing_comma(prev.kind(), next.kind()) { // Removes: trailing comma, newline (incl. surrounding whitespace) edit.delete(TextRange::from_to(prev.range().start(), token.range().end())); - } else if prev.kind() == COMMA && next.kind() == R_CURLY { + } else if prev.kind() == T![,] && next.kind() == T!['}'] { // Removes: comma, newline (incl. surrounding whitespace) let space = if let Some(left) = prev.prev_sibling_or_token() { compute_ws(left.kind(), next.kind()) @@ -116,7 +117,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: SyntaxToken, offset: TextUn fn has_comma_after(node: &SyntaxNode) -> bool { match non_trivia_sibling(node.into(), Direction::Next) { - Some(n) => n.kind() == COMMA, + Some(n) => n.kind() == T![,], _ => false, } } @@ -150,7 +151,7 @@ fn join_single_use_tree(edit: &mut TextEditBuilder, token: SyntaxToken) -> Optio fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool { match (left, right) { - (COMMA, R_PAREN) | (COMMA, R_BRACK) => true, + (T![,], T![')']) | (T![,], T![']']) => true, _ => false, } } diff --git a/crates/ra_ide_api/src/matching_brace.rs b/crates/ra_ide_api/src/matching_brace.rs index bebd16a69..eaa4b620c 100644 --- a/crates/ra_ide_api/src/matching_brace.rs +++ b/crates/ra_ide_api/src/matching_brace.rs @@ -1,13 +1,14 @@ use ra_syntax::{ SourceFile, TextUnit, algo::find_token_at_offset, - SyntaxKind::{self, *}, + SyntaxKind::{self}, ast::AstNode, + T }; pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option { const BRACES: &[SyntaxKind] = - &[L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE]; + &[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>]]; let (brace_node, brace_idx) = find_token_at_offset(file.syntax(), offset) .filter_map(|node| { let idx = BRACES.iter().position(|&brace| brace == node.kind())?; diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index d9a28d2b5..a03b13839 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -1,6 +1,6 @@ use rustc_hash::FxHashSet; -use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind::*, SyntaxElement}; +use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind::*, SyntaxElement, T}; use ra_db::SourceDatabase; use crate::{FileId, db::RootDatabase}; @@ -40,7 +40,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec range_end = sibling.range().end(), + T![!] | IDENT => range_end = sibling.range().end(), _ => (), } } -- cgit v1.2.3