Skip to content

fix(compact): align zero-width hunk context - #512

Open
caenrique wants to merge 2 commits into
esmuellert:mainfrom
caenrique:fix/compact-zero-width-context
Open

fix(compact): align zero-width hunk context#512
caenrique wants to merge 2 commits into
esmuellert:mainfrom
caenrique:fix/compact-zero-width-context

Conversation

@caenrique

Copy link
Copy Markdown
Contributor

Problem

Compact folds can be off by one after a zero-width hunk, so corresponding fold boundaries do not align between the two panes.

Solution

Handle zero-width ranges as boundaries when calculating visible context, and map the first folded line consistently between both sides.

Testing

Added compact-mode tests for zero-width context and fold alignment. The compact test suite passes.

Comment thread lua/codediff/ui/view/compact.lua Outdated
range_end = range_start + 1
end

-- A zero-width range is a boundary between unchanged lines. The formula

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The comments seem to be dead and should remove?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done in 053c99c

esmuellert added a commit that referenced this pull request Sep 4, 2026
## Summary

Add first-class pull request review by number without checking out a
branch or changing the working tree.

```vim
:CodeDiff pr 512
:CodeDiff pr 512 --remote upstream
:CodeDiff pr 512 --base release/3.x
:CodeDiff pr 512 -- lua/codediff
```

## Changes

- discover and fetch provider pull request refs directly through Git
  - GitHub and Azure DevOps: `refs/pull/<number>/{merge,head}`
  - GitLab: `refs/merge-requests/<number>/{merge,head}`
- prefer the provider synthetic merge commit so its parents identify the
review base and head
- fall back to the PR head plus the remote default branch, with `--base`
for non-default targets
- support `--remote`, the existing `--repo`/`-C` override, and Git
pathspecs
- keep fetched commits under `refs/codediff/pull-requests/` and
force-update them after PR force-pushes
- add explicit cache cleanup commands:
  - `:CodeDiff pr clean <number>`
  - `:CodeDiff pr clean --all`
- both support repository selection; cleanup can be scoped with
`--remote`
- separate atomic Git operations from provider-specific pull request
orchestration
- document the command, ref lifecycle, supported providers, and cleanup
behavior

## Benefits

- review a PR from its number with the existing merge-base Explorer
- no checkout, local branch, worktree mutation, provider CLI, or API
token required
- works with existing Git remote authentication, including private
repositories
- supports fork workflows by selecting the target repository remote
- cached refs remain safe for lazy/asynchronous file loading while
remaining explicitly removable

## Testing

- `CODEDIFF_TEST_JOBS=1 ./tests/run_tests.sh` — 108 spec files passed
- pull request integration suite — 12 tests passed against local bare
remotes
- command E2E suite — 24 tests passed
- verified GitHub/Azure DevOps and GitLab ref layouts, merge and head
fallback paths, explicit base selection, non-origin remotes, force-push
updates, pathspecs, invalid/missing PRs, and branch/worktree invariants
- verified targeted cleanup does not remove another PR, remote, or
unrelated `refs/codediff/*` namespace
- mutation-checked provider selection, force-update behavior, merge-base
dispatch, targeted cleanup, and all-ref cleanup
- manually opened GitHub PR #512 end-to-end without checkout
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