Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

util: Fix crate name extraction for `log_error_with_caller` (#35944)

Lukas Wirth9cd5c3656e83
diff --git a/crates/util/src/util.rs b/crates/util/src/util.rs
index 932b519b18d..b526f53ce41 100644
--- a/crates/util/src/util.rs
+++ b/crates/util/src/util.rs
@@ -669,9 +669,12 @@ where
let file = caller.file();
#[cfg(target_os = "windows")]
let file = caller.file().replace('\\', "/");
- // In this codebase, the first segment of the file path is
- // the 'crates' folder, followed by the crate name.
- let target = file.split('/').nth(1);
+ // In this codebase all crates reside in a `crates` directory,
+ // so discard the prefix up to that segment to find the crate name
+ let target = file
+ .split_once("crates/")
+ .and_then(|(_, s)| s.split_once('/'))
+ .map(|(p, _)| p);
log::logger().log(
&log::Record::builder()