Skip to content

cli: Respect --new when opening URLs from the CLI#54408

Merged
tomhoule merged 1 commit into
mainfrom
tomhoule-vltxqkwtlwxl
May 20, 2026
Merged

cli: Respect --new when opening URLs from the CLI#54408
tomhoule merged 1 commit into
mainfrom
tomhoule-vltxqkwtlwxl

Conversation

@tomhoule

Copy link
Copy Markdown
Contributor

zed --new ssh://host/path/to/file only created a new window on the first call. Subsequent invocations silently reused the existing SSH workspace for the same host, which then tried to open the new path against the existing worktree and surfaced a DevServerProjectPathDoesNotExist popup when the path didn't belong to any open worktree.

The CLI correctly translated --new to OpenBehavior::AlwaysNew, but the URL branch of handle_cli_connection dropped the open_behavior. handle_open_request then called open_remote_project (and open_paths_with_positions for file://) with OpenOptions::default(), which is WorkspaceMatching::MatchExact, so any existing SSH window for the same host won the match. The issue applies to file:// URLs and -a / -e / --reuse for URL-shaped arguments in general; --new was just the most visible symptom.

The fix is making sure the translation of OpenRequest is uniform across plain paths and URL-shaped arguments.

Closes #52679.

Release Notes:

  • Fixed zed --new ssh://host/path reusing an existing SSH window instead of opening a new one. This also applied to other URL-shaped path arguments.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 21, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Apr 21, 2026
@tomhoule tomhoule changed the title zed: Respect --new when opening URLs from the CLI cli: Respect --new when opening URLs from the CLI Apr 21, 2026
@tomhoule tomhoule marked this pull request as ready for review April 21, 2026 12:14
@tomhoule tomhoule requested a review from Copilot April 22, 2026 16:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes CLI URL-opening behavior so that --new (and other open-behavior flags like --reuse, -a, -e) are honored uniformly for URL-shaped arguments (e.g. ssh://..., file://...) instead of silently reusing an existing matching workspace/window.

Changes:

  • Thread open_behavior through RawOpenRequestOpenRequest parsing so URL opens retain the requested behavior.
  • Introduce open_options_for_behavior to consistently translate cli::OpenBehavior into workspace::OpenOptions (workspace matching, sidebar behavior, and reuse target window).
  • Update handle_open_request to pass the derived OpenOptions into open_remote_project and open_paths_with_positions, plus add regression/unit tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/zed/src/zed/open_listener.rs Adds open_behavior to open request types, centralizes behavior→options translation, and adds tests/regression coverage.
crates/zed/src/main.rs Ensures URL-based open handling uses the translated OpenOptions (fixing --new reuse for SSH/file URLs).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tomhoule tomhoule force-pushed the tomhoule-vltxqkwtlwxl branch from c6c11ed to 6090959 Compare April 23, 2026 13:49
@tomhoule tomhoule requested a review from Anthony-Eid April 24, 2026 13:44
@tomhoule tomhoule force-pushed the tomhoule-vltxqkwtlwxl branch from 6090959 to 71ac213 Compare May 12, 2026 07:56
@tomhoule tomhoule force-pushed the tomhoule-vltxqkwtlwxl branch 4 times, most recently from 84076a6 to 8bfc8c7 Compare May 19, 2026 13:04
`zed --new ssh://host/path/to/file` only created a new window on the first call. Subsequent invocations silently reused the existing SSH workspace for the same host, which then tried to open the new path against the existing worktree and surfaced a `DevServerProjectPathDoesNotExist` popup when the path didn't belong to any open worktree.

The CLI correctly translated `--new` to `OpenBehavior::AlwaysNew`, but the URL branch of `handle_cli_connection` dropped the `open_behavior`. `handle_open_request` then called `open_remote_project` (and `open_paths_with_positions` for `file://`) with `OpenOptions::default()`, which is `WorkspaceMatching::MatchExact`, so any existing SSH window for the same host won the match. The issue applies to `file://` URLs and `-a` / `-e` / `--reuse` for URL-shaped arguments in general; `--new` was just the most visible symptom.

The fix is making sure the translation of `OpenRequest` is uniform across plain paths and URL-shaped arguments.

Closes #52679.

Release Notes:

- Fixed `zed --new` flag being ignored when opening file, SSH, and Git commit URLs
@tomhoule tomhoule force-pushed the tomhoule-vltxqkwtlwxl branch from 8bfc8c7 to 8a2e6c1 Compare May 19, 2026 13:21
@tomhoule tomhoule added this pull request to the merge queue May 20, 2026
Merged via the queue into main with commit 0f6ebdd May 20, 2026
32 checks passed
@tomhoule tomhoule deleted the tomhoule-vltxqkwtlwxl branch May 20, 2026 07:00
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request May 20, 2026
…4408)

`zed --new ssh://host/path/to/file` only created a new window on the
first call. Subsequent invocations silently reused the existing SSH
workspace for the same host, which then tried to open the new path
against the existing worktree and surfaced a
`DevServerProjectPathDoesNotExist` popup when the path didn't belong to
any open worktree.

The CLI correctly translated `--new` to `OpenBehavior::AlwaysNew`, but
the URL branch of `handle_cli_connection` dropped the `open_behavior`.
`handle_open_request` then called `open_remote_project` (and
`open_paths_with_positions` for `file://`) with
`OpenOptions::default()`, which is `WorkspaceMatching::MatchExact`, so
any existing SSH window for the same host won the match. The issue
applies to `file://` URLs and `-a` / `-e` / `--reuse` for URL-shaped
arguments in general; `--new` was just the most visible symptom.

The fix is making sure the translation of `OpenRequest` is uniform
across plain paths and URL-shaped arguments.

Closes zed-industries#52679.

Release Notes:

- Fixed `zed --new ssh://host/path` reusing an existing SSH window
instead of opening a new one. This also applied to other URL-shaped path
arguments.
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 2, 2026
…4408)

`zed --new ssh://host/path/to/file` only created a new window on the
first call. Subsequent invocations silently reused the existing SSH
workspace for the same host, which then tried to open the new path
against the existing worktree and surfaced a
`DevServerProjectPathDoesNotExist` popup when the path didn't belong to
any open worktree.

The CLI correctly translated `--new` to `OpenBehavior::AlwaysNew`, but
the URL branch of `handle_cli_connection` dropped the `open_behavior`.
`handle_open_request` then called `open_remote_project` (and
`open_paths_with_positions` for `file://`) with
`OpenOptions::default()`, which is `WorkspaceMatching::MatchExact`, so
any existing SSH window for the same host won the match. The issue
applies to `file://` URLs and `-a` / `-e` / `--reuse` for URL-shaped
arguments in general; `--new` was just the most visible symptom.

The fix is making sure the translation of `OpenRequest` is uniform
across plain paths and URL-shaped arguments.

Closes zed-industries#52679.

Release Notes:

- Fixed `zed --new ssh://host/path` reusing an existing SSH window
instead of opening a new one. This also applied to other URL-shaped path
arguments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"zed ssh://foo@bar/bar/buzz.py --new" does not respect new

3 participants