Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
path: Clean up leftover helpers before join_path work (#65792)
Xin Zhao042e0406d33c
diff --git a/Cargo.lock b/Cargo.lockindex 6ba4a4d8bcd..40795fa879e 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -6684,7 +6684,6 @@ dependencies = ["log","notify","parking_lot",- "path","paths","proto","rope",diff --git a/crates/agent/src/tools/tool_permissions.rs b/crates/agent/src/tools/tool_permissions.rsindex 8fb7fea1cf9..db2e9bcb40f 100644--- a/crates/agent/src/tools/tool_permissions.rs+++ b/crates/agent/src/tools/tool_permissions.rs@@ -11,7 +11,7 @@ use project::{Project, ProjectPath};use settings::Settings;use std::path::{Component, Path, PathBuf};use std::sync::Arc;-use util::{normalize_path, paths::component_matches_ignore_ascii_case};+use util::{paths::component_matches_ignore_ascii_case, paths::normalize_path};pub enum SensitiveSettingsKind {Local,diff --git a/crates/dev_container/src/devcontainer_manifest.rs b/crates/dev_container/src/devcontainer_manifest.rsindex a71eda5ca5a..e0d216f9502 100644--- a/crates/dev_container/src/devcontainer_manifest.rs+++ b/crates/dev_container/src/devcontainer_manifest.rs@@ -10,7 +10,7 @@ use regex::Regex;use fs::Fs;use http_client::HttpClient;-use util::{ResultExt, command::Command, normalize_path};+use util::{ResultExt, command::Command, paths::normalize_path};use crate::{DevContainerConfig, DevContainerContext,diff --git a/crates/editor/src/element/header.rs b/crates/editor/src/element/header.rsindex e7b271f6d52..54b670b3b58 100644--- a/crates/editor/src/element/header.rs+++ b/crates/editor/src/element/header.rs@@ -1,3 +1,4 @@+use std::ffi::OsStr;use std::path::Path;use std::rc::Rc;@@ -683,15 +684,23 @@ pub(crate) fn render_buffer_header(let can_open_excerpts = file.is_none_or(|file| file.can_open());let path_style = file.map(|file| file.path_style(cx));let relative_path = buffer.resolve_file_path(include_root, cx);- let (parent_path, filename) = if let Some(path) = &relative_path {- if let Some(path_style) = path_style {- let (dir, file_name) = path_style.split(path);- (dir.map(|dir| dir.to_owned()), Some(file_name.to_owned()))- } else {- (None, Some(path.clone()))+ let (parent_path, filename) = match (&relative_path, path_style) {+ (Some(path), Some(path_style)) => {+ match path_style+ .file_name(Path::new(path))+ .and_then(OsStr::to_str)+ {+ Some(file_name) => (+ path.strip_suffix(file_name)+ .filter(|parent| !parent.is_empty())+ .map(ToOwned::to_owned),+ Some(file_name.to_owned()),+ ),+ None => (None, Some(path.clone())),+ }}- } else {- (None, None)+ (Some(path), None) => (None, Some(path.clone())),+ (None, _) => (None, None),};let focus_handle = editor_read.focus_handle(cx);let colors = cx.theme().colors();diff --git a/crates/extension/src/extension.rs b/crates/extension/src/extension.rsindex ceffef8efef..81d20ca337d 100644--- a/crates/extension/src/extension.rs+++ b/crates/extension/src/extension.rs@@ -15,7 +15,7 @@ use gpui::{App, EntityId, Task};use language::LanguageName;use semver::Version;use task::{SpawnInTerminal, ZedDebugConfig};-use util::rel_path::RelPath;+use util::{paths::normalize_path, rel_path::RelPath};pub use crate::capabilities::*;pub use crate::extension_events::*;@@ -56,7 +56,7 @@ pub trait Extension: Send + Sync + 'static {/// Returns a path relative to this extension's working directory.fn path_from_extension(&self, path: &Path) -> PathBuf {- path::normalize_path(&self.work_dir().join(path))+ normalize_path(&self.work_dir().join(path))}async fn language_server_command(diff --git a/crates/fs/Cargo.toml b/crates/fs/Cargo.tomlindex f8539e791b6..75b65073d60 100644--- a/crates/fs/Cargo.toml+++ b/crates/fs/Cargo.toml@@ -42,7 +42,6 @@ telemetry.workspace = truetempfile.workspace = truetext.workspace = trueutil.workspace = true-path.workspace = truenotify = "9.0.0-rc.4"trash = { git = "https://github.com/zed-industries/trash-rs", rev = "41c6c800d884a89351f3b8856d12894cccee261d" }diff --git a/crates/fs/src/fs.rs b/crates/fs/src/fs.rsindex 893c25fe4f8..7cc7b2f53cf 100644--- a/crates/fs/src/fs.rs+++ b/crates/fs/src/fs.rs@@ -64,7 +64,7 @@ use git::{status::{FileStatus, StatusCode, TrackedStatus, UnmergedStatus},};#[cfg(feature = "test-support")]-use path::normalize_path;+use util::paths::normalize_path;#[cfg(feature = "test-support")]use smol::io::AsyncReadExt;diff --git a/crates/path/src/path.rs b/crates/path/src/path.rsindex 75f03b2af34..e9b69a4946c 100644--- a/crates/path/src/path.rs+++ b/crates/path/src/path.rs@@ -282,17 +282,6 @@ impl PathStyle {}}- pub fn split(self, path_like: &str) -> (Option<&str>, &str) {- let Some(pos) = path_like.rfind(self.primary_separator()) else {- return (None, path_like);- };- let filename_start = pos + self.primary_separator().len();- (- Some(&path_like[..filename_start]),- &path_like[filename_start..],- )- }-pub fn file_name<'a>(&self, path: &'a Path) -> Option<&'a OsStr> {self.components(path).next_back().and_then(|p| match p {Component::Normal(p) => Some(p),@@ -378,36 +367,6 @@ impl PathStyle {}}-/// Normalizes a path by resolving `.` and `..` components without-/// requiring the path to exist on disk (unlike `canonicalize`).-pub fn normalize_path(path: &Path) -> PathBuf {- use std::path::Component;- let mut components = path.components().peekable();- let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {- components.next();- PathBuf::from(c.as_os_str())- } else {- PathBuf::new()- };-- for component in components {- match component {- Component::Prefix(..) => unreachable!(),- Component::RootDir => {- ret.push(component.as_os_str());- }- Component::CurDir => {}- Component::ParentDir => {- ret.pop();- }- Component::Normal(c) => {- ret.push(c);- }- }- }- ret-}-#[cfg(test)]mod tests {use super::*;diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rsindex 7a3978152d2..3ee7cf58e55 100644--- a/crates/project/src/git_store.rs+++ b/crates/project/src/git_store.rs@@ -90,7 +90,7 @@ use task::Shell;use text::{Bias, BufferId, OffsetRangeExt, Rope, ToOffset};use util::{ResultExt, debug_panic,- paths::{PathStyle, SanitizedPath},+ paths::{PathStyle, SanitizedPath, normalize_path},post_inc,rel_path::RelPath,};@@ -10869,7 +10869,7 @@ pub fn worktrees_directory_for_repo(let resolved = if path_style.is_posix() {joined} else {- path::normalize_path(&joined)+ normalize_path(&joined)};let resolved = if path_style.starts_with(resolved.as_path(), repository_anchor_path) {resolveddiff --git a/crates/util/src/paths.rs b/crates/util/src/paths.rsindex 31ef1c9b7b5..d34dd77a0ac 100644--- a/crates/util/src/paths.rs+++ b/crates/util/src/paths.rs@@ -210,6 +210,36 @@ pub fn strip_path_suffix<'a>(base: &'a Path, suffix: &Path) -> Option<&'a Path>None}+/// Normalizes a path by resolving `.` and `..` components without+/// requiring the path to exist on disk (unlike `canonicalize`).+pub fn normalize_path(path: &Path) -> PathBuf {+ use std::path::Component;+ let mut components = path.components().peekable();+ let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {+ components.next();+ PathBuf::from(c.as_os_str())+ } else {+ PathBuf::new()+ };++ for component in components {+ match component {+ Component::Prefix(..) => unreachable!(),+ Component::RootDir => {+ ret.push(component.as_os_str());+ }+ Component::CurDir => {}+ Component::ParentDir => {+ ret.pop();+ }+ Component::Normal(c) => {+ ret.push(c);+ }+ }+ }+ ret+}+/// In memory, this is identical to `Path`. On non-Windows conversions to this type are no-ops. On/// windows, these conversions sanitize UNC paths by removing the `\\\\?\\` prefix.#[derive(Eq, PartialEq, Hash, Ord, PartialOrd)]diff --git a/crates/util/src/util.rs b/crates/util/src/util.rsindex f0d61b35ad5..df08f0420d7 100644--- a/crates/util/src/util.rs+++ b/crates/util/src/util.rs@@ -42,7 +42,6 @@ use unicase::UniCase;pub use gpui_util::*;pub use path::PathExt;-pub use path::normalize_path;pub use path::rel_path;#[cfg(any(test, feature = "test-support"))]