summaryrefslogtreecommitdiff
path: root/src/syntax/ast.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-18 17:50:57 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-18 17:50:57 +0100
commit5d475ae32ede2cc51e361734f186ff3d4372564a (patch)
treea21d2fb755e89a35d1fd9d6ff365121d38a3ecf7 /src/syntax/ast.rs
parentf2b0c5e08d7433d5a1780fee827da0f29c5bc136 (diff)
Attach parameter list span to function
Diffstat (limited to 'src/syntax/ast.rs')
-rw-r--r--src/syntax/ast.rs20
1 files changed, 14 insertions, 6 deletions
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<Item = Param> + '_ {
- 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<Item = Param> + '_ {
+ self.0.children().filter_map(SyntaxNode::cast)
+ }
+}
+
/// A parameter to a closure.
#[derive(Debug, Clone, Hash)]
pub enum Param {