mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Generate only minimal set of ineresting tokens
This commit is contained in:
parent
8d71a6bf0c
commit
4560fe2abf
8 changed files with 61 additions and 1306 deletions
|
@ -80,7 +80,7 @@ impl<N: AstNode> Iterator for AstChildren<N> {
|
|||
}
|
||||
|
||||
mod support {
|
||||
use super::{AstChildren, AstNode, AstToken, SyntaxKind, SyntaxNode, SyntaxToken};
|
||||
use super::{AstChildren, AstNode, SyntaxKind, SyntaxNode, SyntaxToken};
|
||||
|
||||
pub(super) fn child<N: AstNode>(parent: &SyntaxNode) -> Option<N> {
|
||||
parent.children().find_map(N::cast)
|
||||
|
@ -90,10 +90,6 @@ mod support {
|
|||
AstChildren::new(parent)
|
||||
}
|
||||
|
||||
pub(super) fn token<T: AstToken>(parent: &SyntaxNode) -> Option<T> {
|
||||
parent.children_with_tokens().filter_map(|it| it.into_token()).find_map(T::cast)
|
||||
}
|
||||
|
||||
pub(super) fn token2(parent: &SyntaxNode, kind: SyntaxKind) -> Option<SyntaxToken> {
|
||||
parent.children_with_tokens().filter_map(|it| it.into_token()).find(|it| it.kind() == kind)
|
||||
}
|
||||
|
|
|
@ -189,15 +189,15 @@ impl ast::RecordFieldList {
|
|||
impl ast::TypeParam {
|
||||
#[must_use]
|
||||
pub fn remove_bounds(&self) -> ast::TypeParam {
|
||||
let colon = match self.colon() {
|
||||
let colon = match self.colon_token() {
|
||||
Some(it) => it,
|
||||
None => return self.clone(),
|
||||
};
|
||||
let end = match self.type_bound_list() {
|
||||
Some(it) => it.syntax().clone().into(),
|
||||
None => colon.syntax().clone().into(),
|
||||
None => colon.clone().into(),
|
||||
};
|
||||
self.replace_children(colon.syntax().clone().into()..=end, iter::empty())
|
||||
self.replace_children(colon.into()..=end, iter::empty())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use itertools::Itertools;
|
|||
use ra_parser::SyntaxKind;
|
||||
|
||||
use crate::{
|
||||
ast::{self, support, AstNode, AstToken, AttrInput, NameOwner, SyntaxNode},
|
||||
ast::{self, support, AstNode, AttrInput, NameOwner, SyntaxNode},
|
||||
SmolStr, SyntaxElement, SyntaxToken, T,
|
||||
};
|
||||
|
||||
|
@ -327,23 +327,23 @@ impl ast::TypeBound {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn const_question_token(&self) -> Option<ast::Question> {
|
||||
pub fn const_question_token(&self) -> Option<SyntaxToken> {
|
||||
self.syntax()
|
||||
.children_with_tokens()
|
||||
.filter_map(|it| it.into_token())
|
||||
.take_while(|it| it.kind() != T![const])
|
||||
.find_map(ast::Question::cast)
|
||||
.find(|it| it.kind() == T![?])
|
||||
}
|
||||
|
||||
pub fn question_token(&self) -> Option<ast::Question> {
|
||||
pub fn question_token(&self) -> Option<SyntaxToken> {
|
||||
if self.const_token().is_some() {
|
||||
self.syntax()
|
||||
.children_with_tokens()
|
||||
.filter_map(|it| it.into_token())
|
||||
.skip_while(|it| it.kind() != T![const])
|
||||
.find_map(ast::Question::cast)
|
||||
.find(|it| it.kind() == T![?])
|
||||
} else {
|
||||
support::token(&self.syntax)
|
||||
support::token2(&self.syntax, T![?])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -384,12 +384,12 @@ impl ast::MacroCall {
|
|||
}
|
||||
|
||||
impl ast::LifetimeParam {
|
||||
pub fn lifetime_bounds(&self) -> impl Iterator<Item = ast::Lifetime> {
|
||||
pub fn lifetime_bounds(&self) -> impl Iterator<Item = SyntaxToken> {
|
||||
self.syntax()
|
||||
.children_with_tokens()
|
||||
.filter_map(|it| it.into_token())
|
||||
.skip_while(|x| x.kind() != T![:])
|
||||
.filter_map(ast::Lifetime::cast)
|
||||
.filter(|it| it.kind() == T![lifetime])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,6 +6,7 @@ use stdx::SepBy;
|
|||
use crate::{
|
||||
ast::{self, support, AstChildren, AstNode, AstToken},
|
||||
syntax_node::SyntaxElementChildren,
|
||||
SyntaxToken, T,
|
||||
};
|
||||
|
||||
pub trait TypeAscriptionOwner: AstNode {
|
||||
|
@ -63,8 +64,8 @@ pub trait TypeBoundsOwner: AstNode {
|
|||
support::child(self.syntax())
|
||||
}
|
||||
|
||||
fn colon(&self) -> Option<ast::Colon> {
|
||||
support::token(self.syntax())
|
||||
fn colon_token(&self) -> Option<SyntaxToken> {
|
||||
support::token2(self.syntax(), T![:])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue