mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Replace SyntaxKind usage with T! macro where applicable
This commit is contained in:
parent
e1430d822e
commit
e618d12903
12 changed files with 50 additions and 44 deletions
|
@ -5,7 +5,7 @@
|
|||
|
||||
use itertools::Itertools;
|
||||
use rustc_hash::FxHashSet;
|
||||
use syntax::{ast, AstNode, SyntaxKind};
|
||||
use syntax::{ast, AstNode, T};
|
||||
|
||||
use crate::{
|
||||
context::CompletionContext,
|
||||
|
@ -205,8 +205,7 @@ fn complete_lint(
|
|||
fn parse_comma_sep_input(derive_input: ast::TokenTree) -> Result<FxHashSet<String>, ()> {
|
||||
match (derive_input.left_delimiter_token(), derive_input.right_delimiter_token()) {
|
||||
(Some(left_paren), Some(right_paren))
|
||||
if left_paren.kind() == SyntaxKind::L_PAREN
|
||||
&& right_paren.kind() == SyntaxKind::R_PAREN =>
|
||||
if left_paren.kind() == T!['('] && right_paren.kind() == T![')'] =>
|
||||
{
|
||||
let mut input_derives = FxHashSet::default();
|
||||
let mut current_derive = String::new();
|
||||
|
@ -218,7 +217,7 @@ fn parse_comma_sep_input(derive_input: ast::TokenTree) -> Result<FxHashSet<Strin
|
|||
.skip(1)
|
||||
.take_while(|token| token != &right_paren)
|
||||
{
|
||||
if SyntaxKind::COMMA == token.kind() {
|
||||
if T![,] == token.kind() {
|
||||
if !current_derive.is_empty() {
|
||||
input_derives.insert(current_derive);
|
||||
current_derive = String::new();
|
||||
|
|
|
@ -93,11 +93,11 @@ fn completion_match(ctx: &CompletionContext) -> Option<(ImplCompletionKind, Synt
|
|||
// `impl .. { const $0 }`
|
||||
// ERROR 0
|
||||
// CONST_KW <- *
|
||||
SyntaxKind::CONST_KW => 0,
|
||||
T![const] => 0,
|
||||
// `impl .. { fn/type $0 }`
|
||||
// FN/TYPE_ALIAS 0
|
||||
// FN_KW <- *
|
||||
SyntaxKind::FN_KW | SyntaxKind::TYPE_KW => 0,
|
||||
T![fn] | T![type] => 0,
|
||||
// `impl .. { fn/type/const foo$0 }`
|
||||
// FN/TYPE_ALIAS/CONST 1
|
||||
// NAME 0
|
||||
|
@ -121,7 +121,7 @@ fn completion_match(ctx: &CompletionContext) -> Option<(ImplCompletionKind, Synt
|
|||
let impl_def = ast::Impl::cast(impl_item.parent()?.parent()?)?;
|
||||
let kind = match impl_item.kind() {
|
||||
// `impl ... { const $0 fn/type/const }`
|
||||
_ if token.kind() == SyntaxKind::CONST_KW => ImplCompletionKind::Const,
|
||||
_ if token.kind() == T![const] => ImplCompletionKind::Const,
|
||||
SyntaxKind::CONST | SyntaxKind::ERROR => ImplCompletionKind::Const,
|
||||
SyntaxKind::TYPE_ALIAS => ImplCompletionKind::TypeAlias,
|
||||
SyntaxKind::FN => ImplCompletionKind::Fn,
|
||||
|
|
|
@ -5,7 +5,7 @@ use syntax::{
|
|||
ast::{self, LoopBodyOwner},
|
||||
match_ast, AstNode, Direction, NodeOrToken, SyntaxElement,
|
||||
SyntaxKind::*,
|
||||
SyntaxNode, SyntaxToken,
|
||||
SyntaxNode, SyntaxToken, T,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -119,7 +119,7 @@ pub(crate) fn unsafe_is_prev(element: SyntaxElement) -> bool {
|
|||
element
|
||||
.into_token()
|
||||
.and_then(|it| previous_non_trivia_token(it))
|
||||
.filter(|it| it.kind() == UNSAFE_KW)
|
||||
.filter(|it| it.kind() == T![unsafe])
|
||||
.is_some()
|
||||
}
|
||||
#[test]
|
||||
|
@ -131,7 +131,7 @@ pub(crate) fn if_is_prev(element: SyntaxElement) -> bool {
|
|||
element
|
||||
.into_token()
|
||||
.and_then(|it| previous_non_trivia_token(it))
|
||||
.filter(|it| it.kind() == IF_KW)
|
||||
.filter(|it| it.kind() == T![if])
|
||||
.is_some()
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ pub(crate) fn fn_is_prev(element: SyntaxElement) -> bool {
|
|||
element
|
||||
.into_token()
|
||||
.and_then(|it| previous_non_trivia_token(it))
|
||||
.filter(|it| it.kind() == FN_KW)
|
||||
.filter(|it| it.kind() == T![fn])
|
||||
.is_some()
|
||||
}
|
||||
#[test]
|
||||
|
@ -154,7 +154,7 @@ pub(crate) fn for_is_prev2(element: SyntaxElement) -> bool {
|
|||
.into_token()
|
||||
.and_then(|it| previous_non_trivia_token(it))
|
||||
.and_then(|it| previous_non_trivia_token(it))
|
||||
.filter(|it| it.kind() == FOR_KW)
|
||||
.filter(|it| it.kind() == T![for])
|
||||
.is_some()
|
||||
}
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue