cli: Allow opening new files in non-existent parent directories#42328
cli: Allow opening new files in non-existent parent directories#42328SadiqOnGithub wants to merge 5 commits intozed-industries:mainfrom
Conversation
Discussion: zed-industries#42327 Previously, the `zed` CLI would fail when attempting to open a new file if any of its parent directories did not yet exist on filesystem (e.g., `zed path/to/new_dir/new_file.txt` where `path/to/new_dir` does not exist). This failure occurred because the `parse_path_with_position` function unconditionally called `canonicalize()` on the provided argument. `canonicalize()` fails if any component of the path, including intermediate directories, does not exist, causing the CLI to with an error like "No such file or directory". This change modifies the path parsing logic. If `canonicalize()` fails, it now falls back to resolving the path to an absolute relative to the current working directory. This allows a `PathWithPosition` to be constructed with a valid `PathBuf` that can represent file whose parent directories may not yet exist. This correctly shifts the responsibility for creating intermediate directories (and the file itself) from the CLI to the main application, aligning with user expectations and the behavior of other modern editors.
|
We require contributors to sign our Contributor License Agreement, and we don't have @SadiqOnGithub on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
We require contributors to sign our Contributor License Agreement, and we don't have @SadiqOnGithub on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
SadiqOnGithub
left a comment
There was a problem hiding this comment.
May I know why you think those comments were not needed?
Because they are just restating what the code is doing. |
a6c519e to
b460efa
Compare
|
Thank you for this PR and collaborating on another, I have looked at both and decided that #43250 is indeed a better approach. |
Discussion: #42327
Previously, the
zedCLI would fail when attempting to open a new file if any of its parent directories did not yet exist on filesystem (e.g.,zed path/to/new_dir/new_file.txtwherepath/to/new_dirdoes not exist).This failure occurred because the
parse_path_with_positionfunction unconditionally calledcanonicalize()on the provided argument.canonicalize()fails if any component of the path, including intermediate directories, does not exist, causing the CLI to with an error like "No such file or directory".This change modifies the path parsing logic. If
canonicalize()fails, it now falls back to resolving the path to an absolute relative to the current working directory. This allows aPathWithPositionto be constructed with a validPathBufthat can represent file whose parent directories may not yet exist.This correctly shifts the responsibility for creating intermediate directories (and the file itself) from the CLI to the main application, aligning with user expectations and the behavior of other modern editors.
Closes #ISSUE
Release Notes: