Skip to content

feat: Add --reuse/-r flag to CLI for replacing workspace in existing window - #1

Merged
mateonoel2 merged 2 commits into
mainfrom
feat/add-reuse-flag-to-cli
Sep 14, 2025
Merged

feat: Add --reuse/-r flag to CLI for replacing workspace in existing window#1
mateonoel2 merged 2 commits into
mainfrom
feat/add-reuse-flag-to-cli

Conversation

@mateonoel2

@mateonoel2 mateonoel2 commented Sep 14, 2025

Copy link
Copy Markdown
Owner

Closes #ISSUE

it is was still in discussion

Release Notes:

  • Added: --reuse (-r) CLI flag to replace the workspace in an existing window instead of opening a new one

This PR adds a new --reuse (-r) CLI flag that allows users to replace the workspace in an existing Zed window instead of opening a new one or adding files to the current workspace.

What it does

The --reuse flag finds an available local workspace window and replaces its workspace with the newly specified paths. This provides a third workspace opening mode alongside the existing --add and --new flags.

Implementation Details

  • CLI Flag: Added --reuse (-r) flag with proper mutual exclusion with --add and --new
  • Window Replacement: Uses the existing replace_window option in workspace::OpenOptions
  • Window Selection: Reuses the first available local workspace window
  • Fallback Behavior: When no existing windows are found, creates a new window
  • Test Coverage: Added comprehensive test for the reuse functionality

Behavior

  • zed -r file.txt - Replaces the workspace in an available window with file.txt
  • If no windows are open, creates a new window (same as default behavior)
  • Mutually exclusive with -a/--add and -n/--new flags
  • Works with multiple files and directories

Files Changed

  • crates/cli/src/cli.rs - Added reuse field to CliRequest::Open
  • crates/cli/src/main.rs - Added CLI argument definition and parsing
  • crates/zed/src/zed/open_listener.rs - Implemented reuse logic and added tests
  • crates/zed/src/zed/windows_only_instance.rs - Updated for Windows compatibility

Testing

  • ✅ Unit tests pass
  • ✅ Manual testing confirms expected behavior:
    • Works when no windows are open
    • Replaces workspace in existing window
    • Maintains compatibility with existing -a and -n flags
    • Proper help text display

Manual testing proof

In this first video we do a couple of tests:

  • 1: What happens if we use the -r flag when there are no windows open?
    - works as expected. It opens the files in a new window.

  • 2: Does it work as expected if there is already a window open. Does it overrides the workspace?
    - yes it does. When opening a different file it overrides the current window instead of creating a new one.

  • 3: Does the -n flag still works as expected?
    - yes, it creates the project in a new window

  • 4: What about the -a flag?
    - yes, on the last accessed page

  • 5: we do the replace command. It overrides the first opened window, do we want this behavior?
    - It is good enough that it overrides one of the opened windows with the new project. It still makes the user automatically go to the window with the specified files

  • 6: we use the -r command again replacing the workspace with a new one.
    - this indeed worked as expected

more_cli_testing.mp4

In here the we check how the --help flag now displays the new command. (Description was later updated)

comparing_cli_help.mp4

@mateonoel2 mateonoel2 changed the title feat: tests are passing! next stop checking if it works after building feat: Add --reuse/-r flag to CLI for replacing workspace in existing window Sep 14, 2025
@mateonoel2
mateonoel2 marked this pull request as ready for review September 14, 2025 07:50
@mateonoel2
mateonoel2 merged commit e10c427 into main Sep 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant