summaryrefslogtreecommitdiff
path: root/crates/typst-cli/src/compile.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-08-22 14:21:04 +0200
committerLaurenz <laurmaedje@gmail.com>2023-08-22 14:21:04 +0200
commitafc95ed19db8ded044d3b9b916fa0194cb882d0b (patch)
treeae9f5aa62398c1c81efe1f6d046fb2d631cb1c1c /crates/typst-cli/src/compile.rs
parent756bdb623c9deda1458506b1783a66d92f2d9414 (diff)
Virtual path type
Fixes #1937
Diffstat (limited to 'crates/typst-cli/src/compile.rs')
-rw-r--r--crates/typst-cli/src/compile.rs16
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> {