Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Find a file
张小白 cff9ae0bbc
Better absolute path handling (#19727)
Closes #19866

This PR supersedes #19228, as #19228 encountered too many merge
conflicts.

After some exploration, I found that for paths with the `\\?\` prefix,
we can safely remove it and consistently use the clean paths in all
cases. Previously, in #19228, I thought we would still need the `\\?\`
prefix for IO operations to handle long paths better. However, this
turns out to be unnecessary because Rust automatically manages this for
us when calling IO-related APIs. For details, refer to Rust's internal
function
[`get_long_path`](017ae1b21f/library/std/src/sys/path/windows.rs (L225-L233)).

Therefore, we can always store and use paths without the `\\?\` prefix.

This PR introduces a `SanitizedPath` structure, which represents a path
stripped of the `\\?\` prefix. To prevent untrimmed paths from being
mistakenly passed into `Worktree`, the type of `Worktree`’s `abs_path`
member variable has been changed to `SanitizedPath`.

Additionally, this PR reverts the changes of #15856 and #18726. After
testing, it appears that the issues those PRs addressed can be resolved
by this PR.

### Existing Issue
To keep the scope of modifications manageable, `Worktree::abs_path` has
retained its current signature as `fn abs_path(&self) -> Arc<Path>`,
rather than returning a `SanitizedPath`. Updating the method to return
`SanitizedPath`—which may better resolve path inconsistencies—would
likely introduce extensive changes similar to those in #19228.

Currently, the limitation is as follows:

```rust
let abs_path: &Arc<Path> = snapshot.abs_path();
let some_non_trimmed_path = Path::new("\\\\?\\C:\\Users\\user\\Desktop\\project"); 
// The caller performs some actions here:
some_non_trimmed_path.strip_prefix(abs_path);  // This fails
some_non_trimmed_path.starts_with(abs_path);   // This fails too
```

The final two lines will fail because `snapshot.abs_path()` returns a
clean path without the `\\?\` prefix. I have identified two relevant
instances that may face this issue:
-
[lsp_store.rs#L3578](0173479d18/crates/project/src/lsp_store.rs (L3578))
-
[worktree.rs#L4338](0173479d18/crates/worktree/src/worktree.rs (L4338))

Switching `Worktree::abs_path` to return `SanitizedPath` would resolve
these issues but would also lead to many code changes.

Any suggestions or feedback on this approach are very welcome.

cc @SomeoneToIgnore 

Release Notes:

- N/A
2024-11-27 20:22:58 +02:00
.cargo Revert "Use livekit's Rust SDK instead of their swift SDK (#13343)" (#20809) 2024-11-18 11:43:53 +02:00
.cloudflare docs: Document context servers (#21170) 2024-11-25 11:05:14 -05:00
.config
.github chore: Do not produce universal binaries for our releases (#21014) 2024-11-21 23:16:49 +01:00
.zed ci: Move collab to Dockerfile-collab (#18515) 2024-09-30 16:14:26 -04:00
assets Allow splitting the terminal panel (#21238) 2024-11-27 20:22:39 +02:00
crates Better absolute path handling (#19727) 2024-11-27 20:22:58 +02:00
docs docs: Move install rustup callup to top of developing-extensions.md (#21239) 2024-11-27 09:25:43 -05:00
extensions Improve file_types in default.json (#20429) 2024-11-18 19:56:45 -05:00
legal
nix Improve Nix package and shell (#21075) 2024-11-27 20:22:17 +02:00
script chore: Do not produce universal binaries for our releases (#21014) 2024-11-21 23:16:49 +01:00
tooling/xtask chore: Fix several style lints (#17488) 2024-09-06 11:58:39 +02:00
.envrc Improve Nix package and shell (#21075) 2024-11-27 20:22:17 +02:00
.git-blame-ignore-revs
.gitattributes
.gitignore Add script to generate license dependencies as csv (#18411) 2024-09-26 16:21:20 -04:00
.mailmap Update .mailmap (#20729) 2024-11-15 11:05:41 -05:00
Cargo.lock Better absolute path handling (#19727) 2024-11-27 20:22:58 +02:00
Cargo.toml Better absolute path handling (#19727) 2024-11-27 20:22:58 +02:00
clippy.toml chore: Fix some violations of 'needless_pass_by_ref_mut' lint (#18795) 2024-10-07 01:29:58 +02:00
CODE_OF_CONDUCT.md Remove community content from docs and point to zed.dev (#19895) 2024-10-29 09:44:58 -04:00
compose.yml
CONTRIBUTING.md Remove community content from docs and point to zed.dev (#19895) 2024-10-29 09:44:58 -04:00
Cross.toml Add remote server cross compilation (#19136) 2024-10-12 23:23:56 -07:00
debug.plist
default.nix
docker-compose.sql
Dockerfile-collab collab: Remove dependency on X11 (#19079) 2024-10-11 13:28:34 -04:00
Dockerfile-collab.dockerignore ci: Move collab to Dockerfile-collab (#18515) 2024-09-30 16:14:26 -04:00
Dockerfile-cross Add remote server cross compilation (#19136) 2024-10-12 23:23:56 -07:00
Dockerfile-cross.dockerignore Add remote server cross compilation (#19136) 2024-10-12 23:23:56 -07:00
Dockerfile-distros Support More Linux (#18480) 2024-09-30 17:46:21 -04:00
Dockerfile-distros.dockerignore Support More Linux (#18480) 2024-09-30 17:46:21 -04:00
flake.lock Improve Nix package and shell (#21075) 2024-11-27 20:22:17 +02:00
flake.nix Improve Nix package and shell (#21075) 2024-11-27 20:22:17 +02:00
LICENSE-AGPL
LICENSE-APACHE
LICENSE-GPL
livekit.yaml
Procfile
Procfile.postgrest
README.md
renovate.json Migrate Renovate config (#20741) 2024-11-15 14:37:39 -05:00
rust-toolchain.toml
shell.nix
typos.toml Make danger to output less false-positives (#19151) 2024-10-14 01:50:46 +03:00

Zed

CI

Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.


Installation

Packaging status

On macOS and Linux you can download Zed directly or install Zed via your local package manager.

Other platforms are not yet available:

Developing Zed

Contributing

See CONTRIBUTING.md for ways you can contribute to Zed.

Also... we're hiring! Check out our jobs page for open roles.

Licensing

License information for third party dependencies must be correctly provided for CI to pass.

We use cargo-about to automatically comply with open source licenses. If CI is failing, check the following:

  • Is it showing a no license specified error for a crate you've created? If so, add publish = false under [package] in your crate's Cargo.toml.
  • Is the error failed to satisfy license requirements for a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to the accepted array in script/licenses/zed-licenses.toml.
  • Is cargo-about unable to find the license for a dependency? If so, add a clarification field at the end of script/licenses/zed-licenses.toml, as specified in the cargo-about book.