mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-21 16:10:19 +01:00
fb62376caa2fdaeb383e1b89ffa5810fb41c4dbd
13 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
9521840152 |
path: Reimplement PathStyle::join based on the standard library's implementation (#65966)
## Summary Final follow-up of #64149, this PR reimplements `PathStyle::join()` on top of `std::path::PathBuf::push`, via a new `PathStyle`-aware `PathBufExt::styled_push` helper. The old `join_path()` and `join_path_preserving_components()` are removed, and their call sites are migrated as follows: - `join` -> `join` - `join_path` -> `join` + `normalize_lexically` - `join_path_preserving_components` -> `join`, plus `normalize_separators` only where the joined path is displayed to the user I'm confident that the new `join()` mirrors std's behavior. The main thing to be aware of is that the old `join` rejected a rooted right-hand side and returned `None`, while the new one accepts it and handles it: the left-hand side is replaced entirely, except for a root-only operand such as `\b` on Windows, which keeps the left side's prefix (`C:\a` + `\b` = `C:\b`). Because the old `join` rejected rooted right-hand sides, all migrated call sites were audited for `has_root`: the right operand either cannot be rooted by construction, or the call site already guards rooted inputs with `has_root`, or an explicit guard was added here. One edge case was noticed but left unchanged: a drive-relative operand such as `C:foo.rs` is now replaced instead of concatenated (mirroring std). This case was equally unhandled before, so it is left as-is here; adding another check beyond the existing `has_root` guard would not be self-explanatory either. #65911 (git worktree names containing path components) is likewise pre-existing and tracked separately. ## Testing New tests are added for the new `join` method, adapted from the std lib. The tests of the affected caller crates have been run to prevent regressions, but this is not a guarantee. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - N/A |
||
|
|
f2a60bb8b6 |
title_bar: Fix project name shown for repo.git bare clones on Windows remotes (#66199)
## Summary For a repo named `test_repo`, if it is bare cloned without renaming the common dir, the common dir is `test_repo.git`, and Zed treats the directory itself as the identity path: https://github.com/zed-industries/zed/blob/ec86047d67acd6fddd81392f44ed6ebcc6e7f531/crates/project/src/git_store.rs#L10674-L10689 The title bar then uses the identity path to display the project name, with the name determined by the std lib’s method: https://github.com/zed-industries/zed/blob/ec86047d67acd6fddd81392f44ed6ebcc6e7f531/crates/title_bar/src/title_bar.rs#L284-L288 When connecting from a Unix client to a Windows remote host, the identity path could be, for example, `C:\User\test\test_repo.git`. Applying std’s path methods to it yields an extension of `git` and a file stem of `C:\User\test\test_repo`, so the project name is displayed as `C:\User\test\test_repo` instead of `test_repo`. This PR introduces two new `PathStyle` methods to handle retrieving `file_stem()` and `extension()` cross-platform. They mirror the std lib’s behavior using the already introduced Path components. ## Testing New unit tests for `PathStyle::file_stem()` and `PathStyle::extension()` are introduced to guard its behavior. The title bar shown is locally tested: |Before|After| |:--:|:--:| | <img width="390" height="112" alt="Before" src="https://github.com/user-attachments/assets/82c08423-a25e-4cd0-ae74-2614818d47c9" /> |<img width="267" height="147" alt="After" src="https://github.com/user-attachments/assets/b739c801-10ef-49da-90fb-c36233313a66" />| ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - Fixed project names in the title bar for `repo.git` bare clones on remote Windows hosts. |
||
|
|
a4a3a968d1 |
path: Replace normalize with component-based normalization in PathStyle (#65782)
## Summary Follow-up to #64149 and an intermediate step toward the composable join API discussed in https://github.com/zed-industries/zed/pull/63102#issuecomment-6214033056. This PR removes the handwritten `PathStyle::normalize()` and migrates its call sites, then introduces two new methods: `PathStyle::normalize_separators()` and `PathStyle::normalize_lexically()`. `normalize_separators()` collects a path's components into a `PathBuf` for the target `PathStyle`; the `/` to `\` rewrite only happens on Windows, and not inside verbatim paths. `normalize_lexically()` additionally resolves `.` and `..`. The standard library has no direct equivalent of `normalize_separators()`. The closest operation is `Path::components().collect::<PathBuf>()`, but that implementation pushes each component as a path and corrupts verbatim paths on Windows (rust-lang/rust#164467). I rewrote the collection in a dedicated `collect_components()` function that appends each component's raw `OsStr` with a `PathStyle`-aware separator; `normalize_separators()` is a thin wrapper around it. It removes redundant and trailing separators and interior `.` components, and it does not resolve `..`. One thing to note is that it does not normalize the prefix: `//server/share/user/project` becomes `//server/share\user\project`. This is necessary to prevent `//?/` from being transformed into `\\?\`: `//?/C:` is parsed as `UNC("?", "C:")`, while `\\?\C:` is a verbatim path with stricter separator rules. It may still be reasonable to canonicalize other prefixes such as plain UNC or device paths, but that would need an explicit exception for `//?/`; I kept the simpler raw-prefix rule for now. Happy to discuss. `normalize_lexically()` has a counterpart in std `Path::normalize_lexically()`, but that method is still unstable and under development. Combining the current std implementation with the discussion in https://github.com/rust-lang/rust/issues/134694#issuecomment-5780155118, I implemented `PathStyle::normalize_lexically()` to return `PathBuf` instead of `Result<PathBuf>`, preserve leading `..` components, and discard `..` above a root instead of returning an error; this follows the suggestion in that discussion that `a/../..` should normalize to `..` rather than error. It mostly matches the old `PathStyle::normalize()` behavior, with a few intentional differences: a non-empty path that normalizes to nothing now returns `.` instead of an empty path, Windows prefixes are preserved as written, `/` is not treated as a separator inside verbatim paths, and `C:..\worktrees` keeps `..` instead of collapsing to `C:worktrees`. It also normalizes separators. As discussed in https://github.com/zed-industries/zed/pull/63102#issuecomment-6214033056, although these two methods overlap, they expose different layers of normalization that callers can opt into on demand. The next step is to replace the three join helpers (`PathStyle::join`, `PathStyle::join_path`, and `PathStyle::join_path_preserving_components`) with a plain `PathStyle::join` that mirrors `std::path::Path::join`, leaving separator and lexical normalization as explicit steps that callers compose. ## Testing Added tests for both methods across Unix and Windows styles, covering the scenarios described above. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - N/A |
||
|
|
042e0406d3 |
path: Clean up leftover helpers before join_path work (#65792)
## Summary I think we are getting closer to fully making `PathStyle` a mirrored, cross-platform counterpart to `Path` on top of #65782. Before the final step — a separate change focused solely on the `join_path`-related methods — this PR clears up the remaining odds and ends and removes the leftover helpers from the `path` crate. The `normalize_path` function is moved to `crates/util/src/paths.rs`, as it has no cross-platform behavior, so `util` is a more appropriate home for it. `PathStyle::split()` is removed. Its functionality can be replaced by `PathStyle::file_name()` plus stripping the file name from the original path, and since there is only one caller, the migration is straightforward. ## Testing Mostly a refactor. For the only caller of `PathStyle::split()`, the multi-buffer header, I manually tested that the header still renders the file name and parent directory correctly. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - N/A |
||
|
|
5504e87bfd |
workspace: Fix trust scope paths when connecting to Windows hosts from Unix (#63102)
# Objective This is another fix related to the path handling issue when connecting from Unix to Windows, similar to #62038 and #63075, but confined to the path handling in the security modal. The root cause is the same: when using the standard library `Path` API across platforms — especially connecting from Unix to Windows — these `Path` methods give wrong results. The bugs I have observed include: 1. When opening a single file, its parent folder is not shown properly in the project list. 2. When opening a folder, no parent folder is auto-filled into the input field after "Trust all projects in". 3. When Zed runs in debug mode, opening two untrusted folders, checking "Trust parents", and then trusting would result in a panic. ## Solution Use the corresponding methods in `PathStyle`, which is designed for handling paths across platforms, instead of the `Path` methods in the relevant code. ## Testing Built and tested locally, with comparison screenshots attached. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase || Before | After | |:--:|:--:|:--:| | Auto fill |<img width="657" height="343" alt="auto_fill_before" src="https://github.com/user-attachments/assets/e36ca3d5-998c-4bed-94e9-f97dd0e7ebf4" />| <img width="654" height="333" alt="auto_fill_after" src="https://github.com/user-attachments/assets/c8413fb5-d2dd-427a-afb0-9cbebc033742" /> | | Single file | <img width="654" height="322" alt="single_file_before" src="https://github.com/user-attachments/assets/bfe87ab0-bf87-491a-8f85-b5a2681763a9" />| <img width="657" height="325" alt="single_file_after" src="https://github.com/user-attachments/assets/0437cbde-42c3-44f6-847b-abd33e54cd2c" /> | --- Release Notes: - Fixed trusting projects on remote Windows machines from Unix systems |
||
|
|
f929b3f7ce |
path: Reimplement PathStyle::strip_prefix based on std lib's implementation (#65503)
## Summary Another follow-up of #64149 The old `strip_prefix` did not only do the stripping, but also had the functionality to build `RelPath`; this PR removes the `RelPath` building part. It also reimplements this method based on components instead of strings, which gives us the ability to handle non-UTF-8 paths and Windows prefixes reliably. Most of the callers of `PathStyle::strip_prefix()` are replaced by the following chain: ```rust PathStyle::strip_prefix() .ok() .and_then(|path| RelPath::new(path, path_style).ok()) ``` In certain places, RelPath is not needed, and the updated `strip_prefix` gives a direct result. ## Testing Added new tests to guard `PathStyle::strip_prefix`'s functionality. Tests passed for the crates where the callers live. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - N/A |
||
|
|
51a3a0e971 |
path: Distinguish is_absolute and has_root in PathStyle (#65468)
## Summary Follow-up of #64149, Zed currently has three handcrafted, identical `is_absolute()` functions, living in `crates/path/src/path.rs` and `crates/util/src/paths.rs`. They read as follows: https://github.com/zed-industries/zed/blob/93d745668805029476e6d7fbb19652116fed51de/crates/path/src/path.rs#L409-L420 In fact, these handcrafted methods behave like `Path::has_root()` rather than `Path::is_absolute()`. The difference between the two is that `Path::has_root()` only checks whether a path has a root, whereas `Path::is_absolute()` checks whether the path is truly absolute. On Unix, which has a single root, `has_root()` and `is_absolute()` coincide. Windows, however, is multi-rooted (`C:\` and `D:\` are different roots), so a rooted path such as `\temp\path` is not absolute: depending on the working directory, it may resolve to `C:\temp\path` or `D:\temp\path`, which are different paths. This misleading naming can lead to misuse of the API. This PR does three things: 1. Deduplicates the methods, keeping only `is_absolute()` in the `PathStyle` body. 2. Reimplements `PathStyle::has_root()` and `PathStyle::is_absolute()` based on the standard library’s implementations; the former replaces the old `is_absolute()`. 3. Updates some callers of the old `is_absolute()` (now `has_root()`, per step 2) to the new `is_absolute()`, based on each call site’s semantics and the actual behavior of the methods. Steps 1 and 2 are pure refactors; the only functional change is in step 3. I believe this fixes some edge cases — or at least surfaces things that need fixing — though I am not entirely certain that every replacement is correct. ## Testing No new tests are introduced. The refactored parts pass the existing tests in the affected crates. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [ ] Tests cover the new or changed behavior. Release Notes: - N/A |
||
|
|
d544470d1d |
Reduce the dependency footprint (#65176)
Follows-up https://github.com/zed-industries/zed/pull/64862 with similar fixes: * replaces a few dependencies that are almost not used, removes unused dependencies * removed unused features * removes `test-support` dependencies from the regular tree * cleans up build scripts Despite the large diff, the changes are rather mechanical, split by commits. Result: <img width="1172" height="77" alt="image" src="https://github.com/user-attachments/assets/7d8aeb58-7cec-4246-8157-d07fc585f81f" /> Release Notes: - N/A - [GPUI] N/A |
||
|
|
a84689073d |
path: Reimplement PathStyle on the standard library's path implementation (#64149)
# Objective Rust's standard library `Path` API is platform-dependent, so you get wrong results when processing a Windows path on Unix, or vice versa. Zed needs this functionality because we support remote development, where cross-platform path handling is routine. Zed's `PathStyle` takes on this responsibility. But handling paths can be really tricky: we need to handle paths with non-UTF-8 characters, a problem I ran into in #63075. And thanks to Microsoft, there are 5 different kinds of valid path prefixes! Not to mention the `/` and `\` separators, which was another problem I ran into in #63102. So we need to make some changes to the `PathStyle` API. ## Solution I'm not an expert on this low-level API design, or on API design in general. But the people who maintain the Rust standard library are. Since `PathStyle`'s API is largely a cross-platform version of the standard library's `Path`, the most reliable and straightforward approach I could come up with is to bring the standard library's implementation into the Zed repo and make the necessary modifications to make it work cross-platform. It turns out Rust already has a great abstraction: the platform-dependent part of `Path` is packaged under `library/std/src/sys/path` and selected at compile time, while the `Path` implementation just uses the abstracted constants and methods: https://github.com/rust-lang/rust/blob/6474e999898cad2289175e2a7d253f5d0f574fa2/library/std/src/path.rs#L96 So we can add some helper methods to `PathStyle` to represent the compile-time-determined pieces of the standard library. Then we bring in the rest, achieving our goal of making `PathStyle`'s functionality the same as the standard library's, but cross-platform. Overall, the `parent()` and `file_name()` methods I introduced in #62038 have been reimplemented, and a new `starts_with()` method has been added. Their implementations are nearly the same as the ones in the standard library. To make these methods work, the standard library's `Components` struct was added in a new file, `crates/path/src/path_component.rs`, which is the core of reliable path handling; and `crates/path/src/windows_prefix.rs` was added to handle Windows paths. Most of the code in these two files is the same as the standard library's; I only made some small tweaks to make it work with `PathStyle`. ## Testing New tests for `starts_with` have been added. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable --- Release Notes: - N/A |
||
|
|
fa00dccc42 |
Fix project path handling when connecting from Unix to Windows remotes (#62038)
# Objective Follow-up of #61374. Zed now supports Windows as a remote target, but when connecting from a Unix platform to Windows, some path handling still uses the native client's path style (Unix) to construct paths, which causes weird path displays in different areas. One of them is the project path stored in the `settings.json` file, which is related to the open path picker in the codebase: https://github.com/zed-industries/zed/blob/5e1fd392f67e27fa1da91bad43eef7db1a5dec23/crates/open_path_prompt/src/open_path_prompt.rs#L668-L679 For example, if I have a remote project at `D:\code\test_python` and want to open it in remote development, I usually use path completions, with `D:\code\` as the parent path and `test_python` as the selected candidate. Zed directly joins them using `Path::join` on the Unix platform, which results in `D:\code\/test_python`. A second thing I found is the displayed name for the git repo. The related source code is: https://github.com/zed-industries/zed/blob/5e1fd392f67e27fa1da91bad43eef7db1a5dec23/crates/title_bar/src/title_bar.rs#L262-L268 Also taking `D:\code\test_python` as an example: the passed-in `common_dir_abs_path` is `D:\code\test_python\.git`, and `repo_identity_path()` directly uses `Path::file_name()` and `Path::parent()` from the standard library to handle this: https://github.com/zed-industries/zed/blob/5e1fd392f67e27fa1da91bad43eef7db1a5dec23/crates/project/src/git_store.rs#L9956-L9965 Ideally, this function should return `D:\code\test_python`. But due to the platform mismatch, `D:\code\test_python\.git` is returned; after further processing in the title bar, we get `D:\code\test_python\` as the displayed name, while the expected display name is `test_python`. In the past, only Unix-like systems could serve as remote servers, and their path separator (`/`) is valid on Windows, so everything looked fine. But Unix does not support `\` as a valid separator — that's the root cause. We need to use `PathStyle`, which is designed for processing paths across platforms, to deal with these cases. ## Solution - Added new APIs `PathStyle::parent()` and `PathStyle::file_name()`, which serve as replacements for `Path::parent()` and `Path::file_name()` to process paths cross-platform. - Adopted the new APIs in `repo_identity_path()`, and updated the relevant call sites. - For the open path picker, use `PathStyle::join_path()` instead of `Path::join`. ## Testing The added `PathStyle::parent()` and `PathStyle::file_name()` are covered by detailed unit tests. These tests verify that the behavior matches the corresponding methods in `Path`, just independent of the host platform. For the path display issues, I built and tested manually; a comparison is attached in the Showcase section. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase <details> <summary>Click to view showcase</summary> | Content | Before | After | |:--:|:--:|:--:| |title bar|<img width="486" height="272" alt="title_bar_before" src="https://github.com/user-attachments/assets/d14d0e37-a1b8-43ab-b51b-fe9dd1b977eb" /> | <img width="406" height="274" alt="title_bar_after" src="https://github.com/user-attachments/assets/fc9193f4-d42c-47a8-a254-4ed08c806a11" /> | |path storage| <img width="337" height="264" alt="project_path_before" src="https://github.com/user-attachments/assets/3352add3-20df-43b9-8a20-10ee7d96e703" />| <img width="319" height="262" alt="project_path_after" src="https://github.com/user-attachments/assets/fa3d7feb-f393-416a-868d-85eb0af5cfb8" />| |open remote| <img width="554" height="135" alt="open_remote_before" src="https://github.com/user-attachments/assets/62983eca-22ad-472f-8333-8561cfc17357" />|<img width="562" height="176" alt="open_remote_after" src="https://github.com/user-attachments/assets/22528a6b-0e73-4a12-a825-673ba57a63da" /> | </details> ## Other things to note This PR also did a little refactoring: it moved the `PathStyle`-related tests from the `util` crate to the `path` crate, and updated the documentation to reflect that Windows can serve as a remote platform. The recent project picker also suffers from the same cross-platform bug, but it is not fixed here, because a clean fix requires dealing with database storage, unlike the direct API changes made here. I will address it in a follow-up PR. This PR looks very large, but most of the changes are the test migration and the new API implementation. I hope the unit tests and comments can offload some of the burden for reviewers. --- Release Notes: - Fixed project paths being built incorrectly when connecting from Unix machines to Windows remote servers. |
||
|
|
2610332077 |
path: Normalize Windows paths independently of the host platform (#61374)
# Objective Zed's `PathStyle` is designed to handle paths across platforms. Its behavior should depend only on the selected path style, not on the platform where Zed is running. This is essential for remote development, where the local and remote platforms may differ. While fixing bugs involving Windows remote targets, I found that `PathStyle::normalize` does not behave consistently across host platforms. For `PathStyle::Windows`, it delegates to `crate::normalize_path`: https://github.com/zed-industries/zed/blob/914e1c9873b6b85bfeedc5b58e8270885bdd532e/crates/path/src/path.rs#L237-L263 That function uses `Path::components()`, which interprets paths according to the host platform. As a result, when Zed runs on a Unix-like system and connects to a Windows remote, something maybe wrong here. `PathStyle::normalize` should instead interpret paths according to the selected `PathStyle`, independently of the host platform. ## Solution Implement Windows path normalization directly in `PathStyle::normalize` without relying on `std::path::Path` parsing. The new implementation: - Recognizes drive-letter, rooted, relative, and UNC paths. - Treats both `\` and `/` as Windows path separators. - Resolves `.` and `..` components lexically. - Uses `\` as the normalized Windows path separator. - Produces the same result regardless of the host platform. ## Testing New test is added and tested with `cargo test -p util`, this test would fail on current main branch. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable --- Release Notes: - N/A or Added/Fixed/Improved ... |
||
|
|
b5fa67cfb3 |
path: Fix unconditional use of serde in path crate (#61037)
Release Notes: - N/A or Added/Fixed/Improved ... |
||
|
|
f181a2f47b |
Split out RelPath into a separate crate (#61029)
This is necessary to remove some `util` dependencies from crates, as well as better sharing for our projects. This also includes the WIP AbsPath abstraction as well as some bug fixes from internal tooling. Release Notes: - N/A or Added/Fixed/Improved ... |