Skip to content

Add hunk keyword expansion in annotation output - #47

Merged
umputun merged 6 commits into
masterfrom
hunk-keyword-expansion
Apr 7, 2026
Merged

umputun merged 6 commits into
masterfrom
hunk-keyword-expansion

Conversation

@umputun

@umputun umputun commented Apr 7, 2026

Copy link
Copy Markdown
Owner

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

  • add EndLine field to Annotation struct
  • detect "hunk" keyword in annotation text and compute hunk boundaries
  • restrict hunk-end scan to same change type to avoid mixing old/new line number spaces
  • update FormatOutput to render file:start-end (type) ranges
  • fix Store.Add replace path to preserve EndLine on re-annotation

Copilot AI review requested due to automatic review settings April 7, 2026 01:34

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.

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.Annotation with EndLine and update Store.Add replacement 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) in FormatOutput when EndLine > 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.

Comment thread site/docs.html Outdated

<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>

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
<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>

Copilot uses AI. Check for mistakes.
don't remove this validation
```

Each annotation block: `## filename:line (type)` where type is `(+)` added, `(-)` removed, or `(file-level)`.

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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)`.

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +12
## 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)

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Comment thread ui/model_test.go
assert.Equal(t, 2, anns[0].Line)
assert.Equal(t, 3, anns[0].EndLine, "EndLine should be last add line's NewNum")
})

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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")
})

Copilot uses AI. Check for mistakes.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 7, 2026 •

Copy link
Copy Markdown

Deploying revdiff with  Cloudflare Pages  Cloudflare Pages

Latest commit: 92e83fe
Status: ✅  Deploy successful!
Preview URL: https://9b40cf0e.revdiff.pages.dev
Branch Preview URL: https://hunk-keyword-expansion.revdiff.pages.dev

View logs

@umputun
umputun merged commit 8b6f18e into master Apr 7, 2026
3 checks passed
@umputun
umputun deleted the hunk-keyword-expansion branch April 7, 2026 01:41
sanchesfree pushed a commit to sanchesfree/revdiff that referenced this pull request Apr 8, 2026
* 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
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.

2 participants