Repository navigation
Add hunk keyword expansion in annotation output - #47
Conversation
There was a problem hiding this comment.
Pull request overview
Adds “hunk” keyword-driven range expansion to annotation headers so downstream consumers can see the full (start–end) line span for contiguous change blocks without introducing new UI modes.
Changes:
- Extend
annotation.AnnotationwithEndLineand updateStore.Addreplacement semantics to preserve/clear it on re-annotation. - Detect whole-word “hunk” in annotation text and compute an end-line via
Model.hunkEndLine, restricted to the same change type. - Render
## file:start-end (type)inFormatOutputwhenEndLine > 0, and update documentation/examples accordingly.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
annotation/store.go |
Adds EndLine and outputs line-endLine headers when present. |
annotation/store_test.go |
Adds tests for replacement behavior and ranged vs single-line output formatting. |
ui/annotate.go |
Detects “hunk” keyword and populates EndLine; introduces hunkEndLine. |
ui/model_test.go |
Adds coverage for EndLine behavior and hunkEndLine edge cases. |
README.md |
Updates output format example + description to mention range expansion. |
site/docs.html |
Updates output format example + adds explanation of hunk keyword expansion. |
docs/plans/completed/20260406-hunk-keyword-expansion.md |
Adds completed plan document for the feature. |
CLAUDE.md |
Notes Annotation.EndLine behavior in repo structure docs. |
.claude-plugin/skills/revdiff/references/usage.md |
Updates output examples + adds note about range expansion. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| <span class="code-comment">## store.go:18 (-)</span> | ||
| don't remove this validation</code></div> | ||
| <p>Each annotation block: <code>## filename:line (type)</code> where type is <code>(+)</code> added, <code>(-)</code> removed, or <code>(file-level)</code>.</p> |
There was a problem hiding this comment.
The docs still state that each annotation block header is always ## filename:line (type), but headers can now include a line range when EndLine is set (e.g. filename:line-end). Update this sentence to document the optional -end range to avoid contradicting the example and behavior.
| <p>Each annotation block: <code>## filename:line (type)</code> where type is <code>(+)</code> added, <code>(-)</code> removed, or <code>(file-level)</code>.</p> | |
| <p>Each annotation block: <code>## filename:line[-end] (type)</code> where type is <code>(+)</code> added, <code>(-)</code> removed, or <code>(file-level)</code>; <code>-end</code> is included when the annotation covers a line range.</p> |
| don't remove this validation | ||
| ``` | ||
|
|
||
| Each annotation block: `## filename:line (type)` where type is `(+)` added, `(-)` removed, or `(file-level)`. |
There was a problem hiding this comment.
This reference still says each annotation header is always ## filename:line (type), but the output now supports filename:line-end when the hunk keyword expands the range. Please update the description to reflect the optional -end suffix.
| Each annotation block: `## filename:line (type)` where type is `(+)` added, `(-)` removed, or `(file-level)`. | |
| Each annotation block: `## filename:line[-end] (type)` where type is `(+)` added, `(-)` removed, or `(file-level)`. |
| ## Overview | ||
| When annotation text contains keywords like "hunk" or "block", automatically expand the output header to include the full hunk line range. For example, if a user annotates line 43 with "refactor this hunk", the output becomes `## file.go:43-67 (+)` instead of `## file.go:43 (+)`. This gives AI consumers the range context without any new UI modes. | ||
|
|
||
| ## Context | ||
| - `annotation/store.go` - Annotation struct, FormatOutput() builds `## file:line (type)` headers | ||
| - `ui/diffview.go` - findHunks() returns indices of hunk starts in diffLines | ||
| - `ui/collapsed.go` - hunkStartFor() finds which hunk contains a given line index | ||
| - `ui/annotate.go` - diffLineNum() maps DiffLine to display line number | ||
| - Keywords to detect: "hunk", "block" (case-insensitive, whole word) | ||
|
|
There was a problem hiding this comment.
This completed plan still references detecting the keyword "block" (and later lists keywords "hunk" or "block"), but the implementation explicitly removed "block" detection to avoid false positives. Please update this document so it matches the shipped behavior (keyword is whole-word "hunk" only).
| assert.Equal(t, 2, anns[0].Line) | ||
| assert.Equal(t, 3, anns[0].EndLine, "EndLine should be last add line's NewNum") | ||
| }) | ||
|
|
There was a problem hiding this comment.
Tests cover the lowercase "hunk" keyword, but the documented behavior is case-insensitive whole-word matching. Consider adding a test case using an uppercase/mixed-case variant (e.g. "HUNK") to lock in the case-insensitivity contract.
| t.Run("uppercase hunk keyword populates EndLine", func(t *testing.T) { | |
| m := testModel([]string{"a.go"}, nil) | |
| m.tree = newFileTree([]string{"a.go"}) | |
| m.focus = paneDiff | |
| m.currFile = "a.go" | |
| m.diffLines = lines | |
| m.diffCursor = 2 // on "new line" (add, NewNum=2) | |
| m.startAnnotation() | |
| m.annotateInput.SetValue("refactor this HUNK") | |
| m.saveAnnotation() | |
| anns := m.store.Get("a.go") | |
| require.Len(t, anns, 1) | |
| assert.Equal(t, 2, anns[0].Line) | |
| assert.Equal(t, 3, anns[0].EndLine, "EndLine should be last add line's NewNum for uppercase HUNK too") | |
| }) |
Deploying revdiff with
|
| Latest commit: |
92e83fe
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9b40cf0e.revdiff.pages.dev |
| Branch Preview URL: | https://hunk-keyword-expansion.revdiff.pages.dev |
* docs: add hunk keyword expansion plan * feat: add EndLine field to Annotation and update FormatOutput for hunk range display * feat: detect hunk keywords in annotations and populate EndLine * feat: document hunk keyword expansion in output format * fix: remove "block" from hunk keywords to avoid false positives * fix: address Copilot review findings for hunk keyword expansion
Add hunk keyword expansion to annotation output. When annotation text contains the word "hunk", the output header automatically expands to include the full hunk line range (e.g.,
## file.go:43-67 (+)instead of## file.go:43 (+)).Related to #43
EndLinefield toAnnotationstructFormatOutputto renderfile:start-end (type)rangesStore.Addreplace path to preserveEndLineon re-annotation