Feat/better diff viewer

Merged
SO
4mo ago
+978-82

Objective

  • Describe the objective or issue this PR addresses.
  • If you're fixing a specific issue, use "Fixes #X" for each issue as described in the GitHub docs.

Solution

  • Describe the solution used to achieve the objective above.

Testing

  • Did you test these changes? If so, how?
  • Are there any parts that need more testing?
  • How can other people (reviewers) test your changes? Is there anything specific they need to know?
  • If relevant, what platforms did you test these changes on, and are there any important ones you can't test?

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content adheres to Zed's UI standards (UX/UI and icon guidelines)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Showcase

This section is optional. If this PR does not include a visual change or does not add a new user-facing feature, you can delete this section.

  • Help others understand the result of this PR by showcasing your awesome work!
  • If this PR includes a visual change, consider adding a screenshot, GIF, or video
    • A before/after comparison is very useful for changes to existing features!

While a showcase should aim to be brief and digestible, you can use a toggleable section to save space on longer showcases:

Click to view showcase

My super cool demos here


Release Notes:

  • N/A or Added/Fixed/Improved ...

Summary by cubic

Adds an embeddable, view-only diff and a new commit diff preview, while keeping the default interactive diff unchanged. Hardens conflict handling, improves targeted git status refresh, fixes diff preview integration, and adds opt-in performance tracing.

  • New Features

    • ProjectDiffOptions with toggles for hunk controls, review button, git panel addon, index mutations, and conflict view; new deploy_at_with_options/deploy_at_project_path_with_options with ProjectDiffOptions::embedded_view_only() for safe, view-only diffs.
    • CommitDiffPreview workspace item for multi-file commit diffs with syntax highlighting and excerpted hunks; preview buffers are named by display path and the commit_diff_preview module is exported for embedders.
    • Editor API: SplittableEditor::set_delegate_stage_and_restore to delegate stage/unstage/restore actions (used to disable index mutations in embedded mode).
    • Opt-in performance tracing for CommitDiffPreview via CHERRYPICK_DIFF_PREVIEW_TRACE.
  • Bug Fixes

    • Conflict UI no longer panics if the conflict addon is missing; subscriptions are only registered when conflict view is enabled.
    • Improved git status updates with GitStore::refresh_status_for_project_paths, batching path refreshes and setting a fallback active repo when needed.
    • Fixed Zed diff preview integration.
    • Fixed embedded diff review: review button and toolbar are hidden in view-only mode; staging/restore commands are delegated and do not mutate the index; default ProjectDiff behavior remains interactive.

Summary by CodeRabbit

  • New Features
    • Added a commit diff preview workspace item to browse per-file changes in a temporary read-only view.
    • Project diff views are now configurable via options (e.g., hunk controls, review button, conflict integration, and whether index edits are allowed).
    • Status can now be refreshed for multiple project paths at once.
  • Bug Fixes
    • Improved conflict view handling to avoid crashes when conflict tracking isn’t available.
    • Split editors now keep stage/restore behavior aligned and correctly delegate when enabled.