From 30bfdaf0a6cf7c03115a42f26cce9628c2952641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20H=C3=B6lting?= <87192362+moritz-hoelting@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:40:43 +0200 Subject: [PATCH] Add path-absolutize crate for absolute path conversion --- Cargo.toml | 1 + src/base/log.rs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2aa901a..6f2c772 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ derive_more = { version = "0.99.17", default-features = false, features = ["dere enum-as-inner = "0.6.0" getset = "0.1.2" mlua = { version = "0.9.7", features = ["lua54", "vendored"], optional = true } +path-absolutize = "3.1.1" serde = { version = "1.0.197", features = ["derive", "rc"], optional = true } shulkerbox = { path = "../shulkerbox", optional = true} strum = { version = "0.26.2", features = ["derive"] } diff --git a/src/base/log.rs b/src/base/log.rs index 35a9dd7..8ae26b6 100644 --- a/src/base/log.rs +++ b/src/base/log.rs @@ -1,6 +1,7 @@ //! Module containing structures and implementations for logging messages to the user. use colored::Colorize; +use path_absolutize::Absolutize; use std::{fmt::Display, sync::Arc}; use super::source_file::{Location, SourceFile, Span}; @@ -99,7 +100,12 @@ impl<'a, T: std::fmt::Display> Display for SourceCodeDisplay<'a, T> { "-->".cyan().bold(), format_args!( "{}:{}:{}", - self.span.source_file().path().display(), + self.span + .source_file() + .path() + .absolutize() + .unwrap_or_else(|_| std::borrow::Cow::Borrowed(self.span.source_file().path())) + .display(), start_location.line, start_location.column )