diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-07-11 16:24:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-11 14:24:28 +0000 |
| commit | be516867c834d1172e17b3b2b25d70428c3d918b (patch) | |
| tree | 7a930e38671d4b2bec7e26c756e143e20960e2be /crates/typst-syntax | |
| parent | 36042ff222d70349f4c459384790ec40e1103bf9 (diff) | |
Spans for cross-file go-to-definition (#4539)
Diffstat (limited to 'crates/typst-syntax')
| -rw-r--r-- | crates/typst-syntax/src/span.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/crates/typst-syntax/src/span.rs b/crates/typst-syntax/src/span.rs index 8138a316..4d5dd9c3 100644 --- a/crates/typst-syntax/src/span.rs +++ b/crates/typst-syntax/src/span.rs @@ -83,6 +83,15 @@ impl Span { self.0.get() & ((1 << Self::BITS) - 1) } + /// Return `other` if `self` is detached and `self` otherwise. + pub fn or(self, other: Self) -> Self { + if self.is_detached() { + other + } else { + self + } + } + /// 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 { |
