diff options
Diffstat (limited to 'crates/typst-cli/src/compile.rs')
| -rw-r--r-- | crates/typst-cli/src/compile.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/crates/typst-cli/src/compile.rs b/crates/typst-cli/src/compile.rs index 0fa66d62..5b51f422 100644 --- a/crates/typst-cli/src/compile.rs +++ b/crates/typst-cli/src/compile.rs @@ -231,11 +231,23 @@ pub fn print_diagnostics( impl<'a> codespan_reporting::files::Files<'a> for SystemWorld { type FileId = FileId; - type Name = FileId; + type Name = String; type Source = Source; fn name(&'a self, id: FileId) -> CodespanResult<Self::Name> { - Ok(id) + let vpath = id.vpath(); + Ok(if let Some(package) = id.package() { + format!("{package}{}", vpath.as_rooted_path().display()) + } else { + // Try to express the path relative to the working directory. + vpath + .resolve(self.root()) + .and_then(|abs| pathdiff::diff_paths(&abs, self.workdir())) + .as_deref() + .unwrap_or_else(|| vpath.as_rootless_path()) + .to_string_lossy() + .into() + }) } fn source(&'a self, id: FileId) -> CodespanResult<Self::Source> { |
