Skip to content

fix(diff): retry new-side hunk match without blank lines - #1777

Merged
lizhengfeng101 merged 2 commits into
alibaba:mainfrom
Trainingcqy:fix/resolver-blank-hunk-lines
Nov 3, 2026
Merged

lizhengfeng101 merged 2 commits into
alibaba:mainfrom
Trainingcqy:fix/resolver-blank-hunk-lines

Conversation

@Trainingcqy

Copy link
Copy Markdown
Contributor

Description

A comment's line numbers come from matching its existing_code snippet against the diff hunks, falling back to the full new file. splitAndNormalize drops blank lines from the snippet, but extractSideLines keeps them in the hunk, so when the quoted code spans a blank line, the match on the hunk's new side misses the quoted location. The full file match returns the first occurrence, so if the same code appears earlier in the file, the comment is located there.

Fix: when the new side does not match line by line, resolveFromHunk matches it again without its blank lines, and a hit's line range includes the blank lines in between; only if that also misses does it match the old side.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

internal/diff/resolver_test.go adds the table test TestResolveFromHunk_BlankLineRetry, including:

  • An added block spanning a blank line: main gives 2..5, expected 8..11.

  • Code moved into another function with a blank line inserted: main gives 2..3, expected 9..11.

  • make test passes locally

  • Manual testing (describe below)

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

AI/LLM disclosure, Claude Code (Claude Opus 5.5) was used to investigate the failure, prepare the changes, and draft this PR.

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

@chaojixinren chaojixinren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101
lizhengfeng101 merged commit abb7abc into alibaba:main Nov 3, 2026
12 checks passed
kall added a commit to kall/open-code-review that referenced this pull request Nov 3, 2026
No text conflicts and no silent breaks. Upstream added no new calls to
the helpers the branch moved into internal/model and left the filter
algorithms untouched. The internal/diff fixes reach the core commands
through the shared code: `ocr core relocate` calls diff.ResolveComment,
so it gains the blank-line-free new-side retry (alibaba#1777), and `ocr core
diff` goes through GetDiff, so it keeps tracked gitignored files in
workspace mode (alibaba#1837) and splits bare "diff --git" headers (alibaba#1691).
New file types (.jsonc, HAML/Slim/ERB, EJS/Liquid/Nunjucks) and Scala
rules are shared rule data. The branch delta against v1.13.5 is
unchanged. Build, vet, make check and the full -race test suite pass;
coverage is 91.2%.
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