4b489f4ce9ae3edbf28e11f4def0dc28099c33d9
--reuse flag for replacing workspace in existing window (#38131)
Closes #ISSUE it is was still in [discussion](https://github.com/zed-industries/zed/discussions/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
Zed
Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Installation
On macOS, Linux, and Windows you can download Zed directly or install Zed via your local package manager.
Other platforms are not yet available:
- Web (tracking issue)
Developing Zed
- Building Zed for macOS
- Building Zed for Linux
- Building Zed for Windows
- Running Collaboration Locally
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 specifiederror for a crate you've created? If so, addpublish = falseunder[package]in your crate's Cargo.toml. - Is the error
failed to satisfy license requirementsfor 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 theacceptedarray inscript/licenses/zed-licenses.toml. - Is
cargo-aboutunable to find the license for a dependency? If so, add a clarification field at the end ofscript/licenses/zed-licenses.toml, as specified in the cargo-about book.
Description
GPUI – Community Edition maintained by Oak Team
https://gpui-ce.github.io/
257 MiB
Languages
Rust
95.5%
WGSL
1.2%
Metal
1.1%
HLSL
1.1%
Python
0.7%
Other
0.3%