diff options
Diffstat (limited to 'crates/typst-syntax')
| -rw-r--r-- | crates/typst-syntax/src/span.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/crates/typst-syntax/src/span.rs b/crates/typst-syntax/src/span.rs index 14e5e216..8138a316 100644 --- a/crates/typst-syntax/src/span.rs +++ b/crates/typst-syntax/src/span.rs @@ -2,6 +2,8 @@ use std::fmt::{self, Debug, Formatter}; use std::num::NonZeroU64; use std::ops::Range; +use ecow::EcoString; + use crate::FileId; /// A unique identifier for a syntax node. @@ -80,6 +82,14 @@ impl Span { pub const fn number(self) -> u64 { self.0.get() & ((1 << Self::BITS) - 1) } + + /// 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 { + return Err("cannot access file system from here".into()); + }; + Ok(file.join(path)) + } } /// A value with a span locating it in the source code. |
