mirror of
https://github.com/oxalica/nil.git
synced 2024-11-22 11:22:46 +03:00
Rename confusing SyntaxKind::is_*
This commit is contained in:
parent
bb9a748cce
commit
fc91c3f6d6
@ -87,7 +87,7 @@ pub(super) fn pack_bindings(ctx: &mut AssistsCtx<'_>) -> Option<()> {
|
|||||||
let trivia_start =
|
let trivia_start =
|
||||||
std::iter::successors(path_value.syntax().first_token(), |tok| tok.prev_token())
|
std::iter::successors(path_value.syntax().first_token(), |tok| tok.prev_token())
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.take_while(|tok| tok.kind().is_whitespace())
|
.take_while(|tok| tok.kind().is_trivia())
|
||||||
.last()
|
.last()
|
||||||
.map_or_else(
|
.map_or_else(
|
||||||
|| path_value.syntax().text_range().start(),
|
|| path_value.syntax().text_range().start(),
|
||||||
|
@ -23,7 +23,7 @@ pub(super) fn remove_empty_let_in(ctx: &mut AssistsCtx<'_>) -> Option<()> {
|
|||||||
let last_token = node
|
let last_token = node
|
||||||
.in_token()?
|
.in_token()?
|
||||||
.next_token()
|
.next_token()
|
||||||
.filter(|tok| tok.kind().is_whitespace())
|
.filter(|tok| tok.kind().is_space())
|
||||||
.or(node.in_token())?;
|
.or(node.in_token())?;
|
||||||
|
|
||||||
let range = node
|
let range = node
|
||||||
@ -59,4 +59,9 @@ mod tests {
|
|||||||
check_no("let foo = 42;$0 in foo");
|
check_no("let foo = 42;$0 in foo");
|
||||||
check_no("{ foo = let bar = 42;$0 in bar; }");
|
check_no("{ foo = let bar = 42;$0 in bar; }");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn keep_comment() {
|
||||||
|
check("let in$0/*hello*/{ }", expect!["/*hello*/{ }"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,14 +297,14 @@ asts! {
|
|||||||
self.0
|
self.0
|
||||||
.children_with_tokens()
|
.children_with_tokens()
|
||||||
.filter_map(|it| it.into_token())
|
.filter_map(|it| it.into_token())
|
||||||
.find(|it| !it.kind().is_whitespace())
|
.find(|it| !it.kind().is_trivia())
|
||||||
.filter(|tok| tok.kind() == T![let])
|
.filter(|tok| tok.kind() == T![let])
|
||||||
}
|
}
|
||||||
pub fn rec_token(&self) -> Option<SyntaxToken> {
|
pub fn rec_token(&self) -> Option<SyntaxToken> {
|
||||||
self.0
|
self.0
|
||||||
.children_with_tokens()
|
.children_with_tokens()
|
||||||
.filter_map(|it| it.into_token())
|
.filter_map(|it| it.into_token())
|
||||||
.find(|it| !it.kind().is_whitespace())
|
.find(|it| !it.kind().is_trivia())
|
||||||
.filter(|tok| tok.kind() == T![rec])
|
.filter(|tok| tok.kind() == T![rec])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -82,8 +82,8 @@ def! {
|
|||||||
KW_THEN = [then],
|
KW_THEN = [then],
|
||||||
KW_WITH = [with] @KEYWORD_LAST,
|
KW_WITH = [with] @KEYWORD_LAST,
|
||||||
|
|
||||||
// Symbols len=1.
|
// Punctuations len=1.
|
||||||
AT = [@] @SYMBOL_FIRST,
|
AT = [@] @PUNCT_FIRST,
|
||||||
BANG = [!],
|
BANG = [!],
|
||||||
COLON = [:],
|
COLON = [:],
|
||||||
COMMA = [,],
|
COMMA = [,],
|
||||||
@ -105,7 +105,7 @@ def! {
|
|||||||
SLASH = [/],
|
SLASH = [/],
|
||||||
STAR = [*],
|
STAR = [*],
|
||||||
|
|
||||||
// Symbols len=2.
|
// Punctuations len=2.
|
||||||
AND2 = [&&],
|
AND2 = [&&],
|
||||||
DOLLAR_L_CURLY = ["${"],
|
DOLLAR_L_CURLY = ["${"],
|
||||||
EQ2 = [==],
|
EQ2 = [==],
|
||||||
@ -118,8 +118,8 @@ def! {
|
|||||||
QUOTE2 = ["''"],
|
QUOTE2 = ["''"],
|
||||||
SLASH2 = ["//"],
|
SLASH2 = ["//"],
|
||||||
|
|
||||||
// Symbols len=3.
|
// Punctuations len=3.
|
||||||
DOT3 = [...] @SYMBOL_LAST,
|
DOT3 = [...] @PUNCT_LAST,
|
||||||
|
|
||||||
// Literals and identifiers.
|
// Literals and identifiers.
|
||||||
FLOAT,
|
FLOAT,
|
||||||
@ -171,19 +171,29 @@ def! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SyntaxKind {
|
impl SyntaxKind {
|
||||||
|
/// Returns whether this is a SPACE.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_whitespace(self) -> bool {
|
pub fn is_space(self) -> bool {
|
||||||
|
matches!(self, Self::SPACE)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns whether this is a COMMENT or SPACE.
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn is_trivia(self) -> bool {
|
||||||
matches!(self, Self::COMMENT | Self::SPACE)
|
matches!(self, Self::COMMENT | Self::SPACE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns whether this is a keyword.
|
||||||
|
/// Contextual keywords are not considered keywords outside expected contexts.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_keyword(self) -> bool {
|
pub fn is_keyword(self) -> bool {
|
||||||
(Self::KEYWORD_FIRST as u8..=Self::KEYWORD_LAST as u8).contains(&(self as u8))
|
(Self::KEYWORD_FIRST as u8..=Self::KEYWORD_LAST as u8).contains(&(self as u8))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns whether this is a punctuation, including operators and delimiters.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_symbol(self) -> bool {
|
pub fn is_punct(self) -> bool {
|
||||||
(Self::SYMBOL_FIRST as u8..=Self::SYMBOL_LAST as u8).contains(&(self as u8))
|
(Self::PUNCT_FIRST as u8..=Self::PUNCT_LAST as u8).contains(&(self as u8))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ pub fn best_token_at_offset(node: &SyntaxNode, offset: TextSize) -> Option<Synta
|
|||||||
| SyntaxKind::PATH_FRAGMENT
|
| SyntaxKind::PATH_FRAGMENT
|
||||||
| SyntaxKind::STRING_FRAGMENT => 2,
|
| SyntaxKind::STRING_FRAGMENT => 2,
|
||||||
SyntaxKind::STRING_ESCAPE => 3,
|
SyntaxKind::STRING_ESCAPE => 3,
|
||||||
k if k.is_symbol() => 4,
|
k if k.is_punct() => 4,
|
||||||
k if k.is_keyword() => 5,
|
k if k.is_keyword() => 5,
|
||||||
// IDENT, INT, and etc.
|
// IDENT, INT, and etc.
|
||||||
_ => 6,
|
_ => 6,
|
||||||
|
@ -148,12 +148,12 @@ impl<'i> Parser<'i> {
|
|||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.map(|&(k, _)| k)
|
.map(|&(k, _)| k)
|
||||||
.filter(|k| !k.is_whitespace())
|
.filter(|k| !k.is_trivia())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consumes all following whitespaces if any.
|
/// Consumes all following whitespaces if any.
|
||||||
fn ws(&mut self) {
|
fn ws(&mut self) {
|
||||||
while matches!(self.peek(), Some(k) if k.is_whitespace()) {
|
while matches!(self.peek(), Some(k) if k.is_trivia()) {
|
||||||
self.bump();
|
self.bump();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user