Todo:

* [x] Open diffed files as regular buffers
* [x] Update diff when buffers change
* [x] Show diffed filenames in the tab title
* [x] Investigate why syntax highlighting isn't reliably handled for old
text
* [x] remove unstage/restore buttons

Release Notes:

- Adds `zed --diff A B` to show the diff between the two files

---------

Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
Co-authored-by: Agus Zubiaga <agus@zed.dev>
This commit is contained in:
Conrad Irwin 2025-06-18 08:43:23 -06:00 committed by GitHub
parent 2f52e2d285
commit 45b5b2e60d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 655 additions and 35 deletions

View file

@ -46,10 +46,10 @@ use uuid::Uuid;
use welcome::{BaseKeymap, FIRST_OPEN, show_welcome_view};
use workspace::{AppState, SerializedWorkspaceLocation, WorkspaceSettings, WorkspaceStore};
use zed::{
OpenListener, OpenRequest, app_menus, build_window_options, derive_paths_with_position,
handle_cli_connection, handle_keymap_file_changes, handle_settings_changed,
handle_settings_file_changes, initialize_workspace, inline_completion_registry,
open_paths_with_positions,
OpenListener, OpenRequest, RawOpenRequest, app_menus, build_window_options,
derive_paths_with_position, handle_cli_connection, handle_keymap_file_changes,
handle_settings_changed, handle_settings_file_changes, initialize_workspace,
inline_completion_registry, open_paths_with_positions,
};
#[cfg(feature = "mimalloc")]
@ -329,7 +329,12 @@ pub fn main() {
app.on_open_urls({
let open_listener = open_listener.clone();
move |urls| open_listener.open_urls(urls)
move |urls| {
open_listener.open(RawOpenRequest {
urls,
diff_paths: Vec::new(),
})
}
});
app.on_reopen(move |cx| {
if let Some(app_state) = AppState::try_global(cx).and_then(|app_state| app_state.upgrade())
@ -658,15 +663,21 @@ pub fn main() {
.filter_map(|arg| parse_url_arg(arg, cx).log_err())
.collect();
if !urls.is_empty() {
open_listener.open_urls(urls)
let diff_paths: Vec<[String; 2]> = args
.diff
.chunks(2)
.map(|chunk| [chunk[0].clone(), chunk[1].clone()])
.collect();
if !urls.is_empty() || !diff_paths.is_empty() {
open_listener.open(RawOpenRequest { urls, diff_paths })
}
match open_rx
.try_next()
.ok()
.flatten()
.and_then(|urls| OpenRequest::parse(urls, cx).log_err())
.and_then(|request| OpenRequest::parse(request, cx).log_err())
{
Some(request) => {
handle_open_request(request, app_state.clone(), cx);
@ -733,13 +744,14 @@ fn handle_open_request(request: OpenRequest, app_state: Arc<AppState>, cx: &mut
}
let mut task = None;
if !request.open_paths.is_empty() {
if !request.open_paths.is_empty() || !request.diff_paths.is_empty() {
let app_state = app_state.clone();
task = Some(cx.spawn(async move |mut cx| {
let paths_with_position =
derive_paths_with_position(app_state.fs.as_ref(), request.open_paths).await;
let (_window, results) = open_paths_with_positions(
&paths_with_position,
&request.diff_paths,
app_state,
workspace::OpenOptions::default(),
&mut cx,
@ -1027,6 +1039,10 @@ struct Args {
/// URLs can either be `file://` or `zed://` scheme, or relative to <https://zed.dev>.
paths_or_urls: Vec<String>,
/// Pairs of file paths to diff. Can be specified multiple times.
#[arg(long, action = clap::ArgAction::Append, num_args = 2, value_names = ["OLD_PATH", "NEW_PATH"])]
diff: Vec<String>,
/// Sets a custom directory for all user data (e.g., database, extensions, logs).
/// This overrides the default platform-specific data directory location.
/// On macOS, the default is `~/Library/Application Support/Zed`.