From 5d475ae32ede2cc51e361734f186ff3d4372564a Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 18 Mar 2023 17:50:57 +0100 Subject: Attach parameter list span to function --- src/syntax/ast.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/syntax') diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 760a6499..59205efb 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -1504,12 +1504,8 @@ impl Closure { } /// The parameter bindings. - pub fn params(&self) -> impl DoubleEndedIterator + '_ { - self.0 - .children() - .find(|x| x.kind() == SyntaxKind::Params) - .map_or([].iter(), |params| params.children()) - .filter_map(SyntaxNode::cast) + pub fn params(&self) -> Params { + self.0.cast_first_match().unwrap_or_default() } /// The body of the closure. @@ -1518,6 +1514,18 @@ impl Closure { } } +node! { + /// A closure's parameters: `(x, y)`. + Params +} + +impl Params { + /// The parameter bindings. + pub fn children(&self) -> impl DoubleEndedIterator + '_ { + self.0.children().filter_map(SyntaxNode::cast) + } +} + /// A parameter to a closure. #[derive(Debug, Clone, Hash)] pub enum Param { -- cgit v1.2.3