cli: Add --reuse flag for replacing workspace in existing window - #38131
Conversation
feat: Add --reuse/-r flag to CLI for replacing workspace in existing window
This comment was marked as spam.
This comment was marked as spam.
--reuse flag for replacing workspace in existing window
kevinnkansah
left a comment
There was a problem hiding this comment.
These are the intended functionalities i wanted in Zed
Updated the thread spawning mechanism for the CLI receiver to use `thread::Builder` for improved clarity and customization. This change enhances the readability of the code while maintaining the existing functionality. Release Notes: - Refactored thread spawning to use `thread::Builder` instead of `thread::spawn`.
Introduced a new `reuse` parameter in the CLI's main function to allow for reusing existing workspaces. This enhancement improves user experience by providing more flexibility in workspace management. Release Notes: - Added `reuse` option to the CLI for workspace handling.
|
Thanks for this! |
|
thank you @mateonoel2 i no longer require vs code! |
|
Thanks. This might not seem such a big change, but it shaves off a couple seconds many times a day for me. |
|
amazing feature! |
|
I'm really disappointed that you made this the default behavior. I'm a CLI first user and my workflow is to change into a directory and then do |
@olafgeibig |
It asked you what the default should be the first time you ran it after the update. You must have just 'enter'-ed your way past it. |
|
…ed-industries#38131) Closes #ISSUE it is was still in [discussion](zed-industries#37983) 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 #### 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 https://github.com/user-attachments/assets/f1cd7f4b-f4af-4da2-a755-c0be7ce96c0d #### In here the we check how the --help flag now displays the new command. (Description was later updated) https://github.com/user-attachments/assets/a8a7a288-d926-431b-a9f9-a8c3d909a2ec
Closes #ISSUE
it is was still in discussion
Release Notes:
--reuse(-r) CLI flag to replace the workspace in an existing window instead of opening a new oneThis 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
--reuseflag 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--addand--newflags.Implementation Details
--reuse(-r) flag with proper mutual exclusion with--addand--newreplace_windowoption inworkspace::OpenOptionsBehavior
zed -r file.txt- Replaces the workspace in an available window withfile.txt-a/--addand-n/--newflagsFiles Changed
crates/cli/src/cli.rs- Addedreusefield toCliRequest::Opencrates/cli/src/main.rs- Added CLI argument definition and parsingcrates/zed/src/zed/open_listener.rs- Implemented reuse logic and added testscrates/zed/src/zed/windows_only_instance.rs- Updated for Windows compatibilityTesting
-aand-nflagsManual testing
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