Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Hunky DoryNew to Visual Studio Code? Get it now.
Hunky Dory

Hunky Dory

shakenfist

|
4 installs
| (0) | Free
Keeps the @@ hunk headers in a patch file correct while you edit it.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Hunky Dory

A VS Code extension that keeps the @@ hunk headers in a patch file correct while you edit it.

If you maintain patches as source -- a _patches/ directory, a quilt series, a distribution package -- then editing one means updating arithmetic by hand:

@@ -86,11 +86,12 @@ jpeg_compression = {{ nova_spice_jpeg_compression }}
                 ^^
                 add a line to the body and this has to change too

Get it wrong in one direction and git rejects the patch. Get it wrong in the other and git silently truncates the hunk and applies the wrong content, which is the failure that costs an afternoon. Hunky Dory does the arithmetic for you as you type.

Emacs has had this in diff-mode for decades. VS Code did not, so here it is.

Install

git clone https://github.com/shakenfist/hunkydory
cd hunkydory
npm install && npm run package
code --install-extension hunkydory-*.vsix

Use

Open any .patch or .diff file and edit it. Headers correct themselves about 200ms after you stop typing, except the one your cursor is sitting on -- that one is left alone until you move away, so it never fights you.

  • Hunky Dory: Recount hunk headers fixes the whole file, cursor line included.
  • Stale headers show up in the Problems panel.
  • The status bar shows which hunk you are in and its line counts.
Setting Default Meaning
hunkydory.mode live live, onSave, or manual.
hunkydory.diagnostics true Report stale headers, and any that cannot be recounted, as warnings.
hunkydory.statusBar true Show the current hunk's counts.

Correctness

The counting rules have more edge cases than they look like they do: empty ranges (file creation and deletion, git diff -U0 insertions), the elided ,1, git's -- signature line, deleted comments that read as file headers, missing trailing newlines, blank context lines that lost their leading space, and two cases that are genuinely ambiguous.

So the tests are concrete cases rather than opinions. Most of them are patches that actually broke, down to scrambling every count in one and requiring the recounter to put it back exactly; the rest cover what a real patch set never happens to contain, such as CRLF line endings. On top of that, npm run corpus runs the recounter over a directory of real patches -- the OpenStack set it was developed against, 187 of them as this is written -- and requires every one to round trip byte identically.

npm test                                         # unit tests
HUNKYDORY_CORPUS=/path/to/patches npm run corpus # regression corpus

Documentation

  • Hunk header format -- what the numbers mean and every rule that turned out to matter.
  • The ambiguous cases -- why a blank line, and rarely a deleted comment, cannot be resolved from the body alone, and what we do about it.
  • Testing -- the tests, the corpus, and the edit fuzzer that has git judge an edited patch.
  • Architecture -- how the pieces fit together.

Related

patchutils solves the same problem from a shell: recountdiff recomputes counts, editdiff fixes up after $EDITOR, and rediff uses the pre-edit patch as a reference -- which lets it detect a deleted context line, the one thing no after-the-fact recounter can see.

License

Apache 2.0.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft