mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Complete params
This commit is contained in:
parent
58480b9190
commit
4798a89a12
10 changed files with 328 additions and 239 deletions
|
@ -682,6 +682,28 @@ impl<'a> AstNode<'a> for IndexExpr<'a> {
|
|||
|
||||
impl<'a> IndexExpr<'a> {}
|
||||
|
||||
// ItemList
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct ItemList<'a> {
|
||||
syntax: SyntaxNodeRef<'a>,
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a> for ItemList<'a> {
|
||||
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
ITEM_LIST => Some(ItemList { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> ItemList<'a> {
|
||||
pub fn items(self) -> impl Iterator<Item = ModuleItem<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
}
|
||||
|
||||
// Label
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Label<'a> {
|
||||
|
@ -956,9 +978,9 @@ impl<'a> AstNode<'a> for Module<'a> {
|
|||
|
||||
impl<'a> ast::NameOwner<'a> for Module<'a> {}
|
||||
impl<'a> ast::AttrsOwner<'a> for Module<'a> {}
|
||||
impl<'a> Module<'a> {
|
||||
pub fn items(self) -> impl Iterator<Item = ModuleItem<'a>> + 'a {
|
||||
super::children(self)
|
||||
impl<'a> ast::FnDefOwner<'a> for Module<'a> {}
|
||||
impl<'a> Module<'a> {pub fn item_list(self) -> Option<ItemList<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1593,15 +1615,12 @@ impl<'a> AstNode<'a> for Root<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> ast::FnDefOwner<'a> for Root<'a> {}
|
||||
impl<'a> Root<'a> {
|
||||
pub fn items(self) -> impl Iterator<Item = ModuleItem<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
|
||||
pub fn functions(self) -> impl Iterator<Item = FnDef<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
|
||||
pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
|
|
|
@ -32,6 +32,12 @@ pub trait ArgListOwner<'a>: AstNode<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait FnDefOwner<'a>: AstNode<'a> {
|
||||
fn functions(self) -> Box<Iterator<Item=FnDef<'a>> + 'a> {
|
||||
Box::new(children(self))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TypeParamsOwner<'a>: AstNode<'a> {
|
||||
fn type_param_list(self) -> Option<TypeParamList<'a>> {
|
||||
child_opt(self)
|
||||
|
|
|
@ -238,9 +238,9 @@ Grammar(
|
|||
],
|
||||
ast: {
|
||||
"Root": (
|
||||
traits: [ "FnDefOwner" ],
|
||||
collections: [
|
||||
["items", "ModuleItem"],
|
||||
["functions", "FnDef"],
|
||||
["modules", "Module"],
|
||||
]
|
||||
),
|
||||
|
@ -271,10 +271,11 @@ Grammar(
|
|||
] ),
|
||||
"TraitDef": ( traits: ["NameOwner", "AttrsOwner"] ),
|
||||
"Module": (
|
||||
traits: ["NameOwner", "AttrsOwner"],
|
||||
collections: [
|
||||
["items", "ModuleItem"]
|
||||
]
|
||||
traits: ["NameOwner", "AttrsOwner", "FnDefOwner" ],
|
||||
options: [ "ItemList" ]
|
||||
),
|
||||
"ItemList": (
|
||||
collections: [ ["items", "ModuleItem"] ]
|
||||
),
|
||||
"ConstDef": ( traits: [
|
||||
"NameOwner",
|
||||
|
|
|
@ -23,7 +23,7 @@ pub(super) fn pattern(p: &mut Parser) {
|
|||
}
|
||||
|
||||
const PAT_RECOVERY_SET: TokenSet =
|
||||
token_set![LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW];
|
||||
token_set![LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW, R_PAREN, COMMA];
|
||||
|
||||
|
||||
fn atom_pat(p: &mut Parser) -> Option<CompletedMarker> {
|
||||
|
|
|
@ -8,6 +8,9 @@ pub(super) const TYPE_FIRST: TokenSet =
|
|||
paths::PATH_FIRST,
|
||||
];
|
||||
|
||||
const TYPE_RECOVERY_SET: TokenSet =
|
||||
token_set![R_PAREN, COMMA];
|
||||
|
||||
pub(super) fn type_(p: &mut Parser) {
|
||||
match p.current() {
|
||||
L_PAREN => paren_or_tuple_type(p),
|
||||
|
@ -23,7 +26,7 @@ pub(super) fn type_(p: &mut Parser) {
|
|||
L_ANGLE => path_type(p),
|
||||
_ if paths::is_path_start(p) => path_type(p),
|
||||
_ => {
|
||||
p.err_and_bump("expected type");
|
||||
p.err_recover("expected type", TYPE_RECOVERY_SET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue