Make ast::Call::span() and arguments_span() more robust

This commit is contained in:
Devyn Cairns 2024-07-19 04:50:07 -07:00
parent 4665323bb4
commit 019eff8ea1
No known key found for this signature in database

View File

@ -110,17 +110,11 @@ impl Call {
/// If there are one or more arguments the span encompasses the start of the first argument to /// If there are one or more arguments the span encompasses the start of the first argument to
/// end of the last argument /// end of the last argument
pub fn arguments_span(&self) -> Span { pub fn arguments_span(&self) -> Span {
let past = self.head.past(); if self.arguments.is_empty() {
self.head.past()
let start = self } else {
.arguments Span::merge_many(self.arguments.iter().map(|a| a.span()))
.first() }
.map(|a| a.span())
.unwrap_or(past)
.start;
let end = self.arguments.last().map(|a| a.span()).unwrap_or(past).end;
Span::new(start, end)
} }
pub fn named_iter( pub fn named_iter(
@ -341,27 +335,7 @@ impl Call {
} }
pub fn span(&self) -> Span { pub fn span(&self) -> Span {
let mut span = self.head; self.head.merge(self.arguments_span())
for positional in self.positional_iter() {
if positional.span.end > span.end {
span.end = positional.span.end;
}
}
for (named, _, val) in self.named_iter() {
if named.span.end > span.end {
span.end = named.span.end;
}
if let Some(val) = &val {
if val.span.end > span.end {
span.end = val.span.end;
}
}
}
span
} }
} }