Repository navigation
Description
Prerequisites
- I have searched for duplicate or closed issues
- I have read the contributing guidelines
Describe the issue
Since 1.3.0, parsePatchFiles runs realignChangeContentBySimilarity on every parsed file, and its slideBlankBoundaryBlocksUp step moves a pure-blank insert or delete to the top of its blank run. It runs on the read-only parse path too, so a literal git patch comes back with the + on a different line than git put it. parseDiffFromFile on the same two texts does the same.
Expected: processFile reports the change on the line the patch states (new line 16 below), the way 1.2.12, git, jsdiff's structuredPatch and github.com all do.
Actual (1.4.3): the change is reported on new line 15.
Row counts and layout are unchanged, so nothing throws, but in a viewer the green row is one line off what github.com shows for the same PR: a comment placed on the green row posts to a line GitHub renders as unchanged context, and a thread GitHub anchors to line 16 lands on a context row directly under the green one.
The slide's docstring says it exists for the editor (a blank inserted after pressing Enter should read as the caret's line). That is reasonable for an edit session, but the parser is also what every read-only FileDiff / CodeView renders from, and there is no option to turn it off. Introduced in #970, reshaped in #978.
Ask: gate the realignment on an active edit session (or an explicit parseDiffOptions flag), or leave parsed hunks as the patch states them and apply the slide only to the editor's live buffer.
Reproduction
Pure parser bug, no DOM involved, so a Node script is the full reduction:
// node repro.mjs (npm i @pierre/[email protected]; compare with @1.2.12)
import { processFile } from '@pierre/diffs';
const patch = `diff --git a/x.ts b/x.ts
--- a/x.ts
+++ b/x.ts
@@ -13,6 +13,7 @@
// the cheap failure is charging full price for a discount we could not see,
// and a provider that renames a field should not silently start billing double.
+
/** One completion's token cost, split by what it actually costs to serve. */
export interface CompletionUsage {
/** Prompt tokens the upstream had to process, cache reads EXCLUDED. */
`;
const d = processFile(patch, { isGitDiff: true });
const change = d.hunks[0].hunkContent.find((c) => c.type === 'change');
console.log(change.additionLineIndex);
// 1.2.12: 3 (hunk-relative; new line 16, as in the patch)
// 1.4.3: 2 (new line 15)What browser(s) are you seeing the problem on?
Other
What version of @pierre/diffs are you using?
1.4.3 (present from 1.3.0; 1.2.12 is correct)
Activity
[-][diffs] `processFile` reports a blank-line change one line off the patch it was given (since 1.3.0)[/-][+]Bug: processFile reports a blank-line change one line off the patch it was given (since 1.3.0)[/+]fix(diffs): preserve parsed blank-line change positions (pierrecomput…