Skip to content

fix(view): apply auto_close_on_empty whenever the view empties - #332

Open
tummetott wants to merge 1 commit into
dlyongemallo:mainfrom
tummetott:feat/close-on-empty-view
Open

tummetott wants to merge 1 commit into
dlyongemallo:mainfrom
tummetott:feat/close-on-empty-view

Conversation

@tummetott

Copy link
Copy Markdown

The policy only ran after staging actions taken in the file panel, so a view stayed open after a commit, and opening one against an empty comparison left an empty panel behind.

Run the policy on every file update so it applies however the view was emptied, and gate it on the whole file list rather than the working bucket alone, since staged entries are still shown.

A view that would hold no files reports Nothing to display. instead of opening.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The update-driven close path mishandles jj views and lacks regression coverage.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

This PR moves auto_close_on_empty into the Diffview file-update path so it can respond when a comparison becomes empty outside a staging action.

Changes:

  • Check the full file list before closing, so staged entries keep the view open.
  • Report “Nothing to display.” for an initially empty comparison.
  • Update the option documentation and a test stub.
File Description
lua/​diffview/​tests/​functional/​diff_view_spec.lua Adds a staged bucket to an existing test stub.
lua/​diffview/​scene/​views/​diff/​listeners.lua Runs the close policy after file updates and waits for file loading to finish.
lua/​diffview/​config.lua Revises the option description and default comment.
doc/​diffview.txt Explains the revised close behavior.
doc/​diffview_defaults.txt Updates the default-config comment.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lua/diffview/scene/views/diff/listeners.lua Outdated
Comment thread lua/diffview/scene/views/diff/listeners.lua Outdated
The policy only ran after staging actions taken in the file panel, so a
view stayed open after a commit, and opening one against an empty
comparison left an empty panel behind.

Run the policy on every file update so it applies however the view was
emptied, and gate it on the whole file list rather than the `working`
bucket alone, since staged entries are still shown. A view that would
hold no files reports `Nothing to display.` instead of opening.

Index-less adapters (jj) keep a resolved file in `working` as the
resolution artifact, so emptiness cannot be the gate there. Pick the
fallback by trigger rather than by adapter: only the conflict resolution
action consults the `had_conflicts` latch, which stays set for the life
of the view and would otherwise close the view on an unrelated refresh.
@tummetott
tummetott force-pushed the feat/close-on-empty-view branch from fc42615 to dfbb696 Compare October 2, 2026 08:46
@tummetott

Copy link
Copy Markdown
Author

Resolved the flagged conflicts

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Initially empty comparisons still execute opening hooks, and the documentation overstates protection for unsaved stage edits.

2 open findings
2 resolved since last review

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread doc/diffview.txt
Automatically close a Diffview that holds no files, and report that
there is nothing to display instead of opening one that would.

A view with unsaved stage buffers is kept open until they are written.
Comment on lines +234 to +235
if not was_initialized and view.files:len() == 0 then
utils.info("Nothing to display.")
@dlyongemallo

Copy link
Copy Markdown
Owner

It seems that the proposed changes includes both a bug fix and a change in behaviour, and these should be separated.

The bug fix (catching external events like git commit that empty the view, and no longer considering a view holding only staged entries to be empty) bring the auto_close_on_empty in line with what the name promises, so that's good. It might surprise users who are used to not having an external git commit affect the existing tab, but arguably the former behaviour didn't match the option name, which is opt-in.

However, showing "Nothing to display" on opening against an empty comparison is a new behavioural change. The promise is to close on empty, not to decline on open when empty, and the change breaks the case where a user has deliberate run DiffviewOpen on a range that they believe is empty (e.g., to confirm two branches are identical after an operation) to get an empty view. The change breaks an invariant: previously, every DiffviewOpen opened a tab, and there may be processes downstream which depend on this.

The bug fix should go in, but the behaviour change needs a design review.

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.

3 participants