summaryrefslogtreecommitdiff
path: root/crates/typst-syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-syntax')
-rw-r--r--crates/typst-syntax/src/span.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/crates/typst-syntax/src/span.rs b/crates/typst-syntax/src/span.rs
index 4d5dd9c3..85745f60 100644
--- a/crates/typst-syntax/src/span.rs
+++ b/crates/typst-syntax/src/span.rs
@@ -92,6 +92,13 @@ impl Span {
}
}
+ /// Find the first non-detached span in the iterator.
+ pub fn find(iter: impl IntoIterator<Item = Self>) -> Self {
+ iter.into_iter()
+ .find(|span| !span.is_detached())
+ .unwrap_or(Span::detached())
+ }
+
/// Resolve a file location relative to this span's source.
pub fn resolve_path(self, path: &str) -> Result<FileId, EcoString> {
let Some(file) = self.id() else {