feat(commands): diff the current buffer against its last save - #430
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
:Diff files {left}is documented as taking the current buffer as its new side, and that is how it was described when the subcommand was added, but the implementation resolves that buffer to its name and then reads the name back from disk. Both sides of a single-path invocation are therefore disk reads: unsaved changes are invisible, and naming the current file compares it to itself and always reports no changes. That also contradicts the claim that the form mirrors:Diff {rev}, which does substitute live buffer content for the worktree endpoint. Nothing in the command surface spells "compare this buffer to its last save".Solution
Apply the rule
:Diffalready follows to:Diff files: a named path is read from disk, and a side the user did not name is the current buffer. The new side of a single-path invocation becomes the buffer's live content, and a bare:Diff filesalso defaults the old side to that buffer's file on disk, so it compares the buffer to its last save. Two named paths behave exactly as before.A buffer-backed side reads as
buffer:{name}in the view name, the list title, and messages, while the diff header keeps real paths so hunk and path parsing are untouched. Thefilessource records the buffer it was opened against, so reloading the view re-reads that buffer instead of quietly reverting to disk, and falls back to the path once the buffer is gone. Difftastic takes the content-based span maps for a buffer-backed side, since the path-based ones can only see disk, and a named buffer that has never been written is no longer refused as unreadable.Closes #429.