opencode-nvim-diff-review 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -155,7 +155,19 @@ The review operates at the **hunk level** rather than the file level. This means
155
155
  - Small files with a single change are naturally one review item
156
156
  - The agent can filter out trivial hunks (e.g., import reordering) from the review
157
157
 
158
- Hunks are retrieved by running `git diff -U0` and parsing the output with diffview.nvim's built-in unified diff parser (`diffview.vcs.utils.parse_diff`). The `-U0` flag produces zero-context hunks, giving exact change boundaries.
158
+ Hunks are retrieved by running `git diff -U0` and parsing the output with diffview.nvim's built-in unified diff parser (`diffview.vcs.utils.parse_diff`). The `-U0` flag produces zero-context hunks, giving exact change boundaries. (Note: `-U0` omits the count in hunk headers when it's 1, e.g., `@@ -134 +134,4 @@`. The plugin normalizes these to the `N,M` form before parsing.)
159
+
160
+ ### Hunk-focus folding
161
+
162
+ When navigating to a hunk, the plugin folds all other regions of the file so only the target hunk is visible — similar to `git add -p`. This is achieved by:
163
+
164
+ 1. Switching both diff windows from `foldmethod=diff` to `foldmethod=manual`
165
+ 2. Creating two manual folds: one above the hunk and one below
166
+ 3. Showing 5 lines of context above and below the hunk
167
+
168
+ The fold highlight is overridden with a custom `DiffviewDiffFoldedReview` highlight group (linked to `Comment` by default) so fold lines look like muted separators rather than diff modifications. Users can override this highlight group in their colorscheme.
169
+
170
+ Line numbers are switched to absolute (`number`, no `relativenumber`) during hunk focus so they match the line ranges shown in the hunk headers.
159
171
 
160
172
  ### Review queue
161
173
 
@@ -172,7 +184,7 @@ The Lua (Neovim) side is stateless — it provides functions to query hunks and
172
184
  - **State queries via global Lua functions**: `DiffviewState()`, `DiffviewHunks()`, and `DiffviewGoTo()` are registered as globals so they can be called via `luaeval()` from Neovim's `--remote-expr` without needing the module require path.
173
185
  - **Wrap-around prevention**: The tool checks queue bounds before navigating and refuses to advance past the first/last item.
174
186
  - **Buffer cleanup on close**: diffview.nvim intentionally keeps local file buffers open after closing (so you can continue editing). The plugin tracks which buffers existed before the review and removes any new ones on close — unless they have unsaved edits.
175
- - **Small delays after navigation**: 300ms sleeps after diffview commands to let the UI update before querying state. Without this, the state query can return stale data.
187
+ - **Async cursor positioning**: `DiffviewGoTo` stores a pending target and applies it via a `DiffviewDiffBufWinEnter` autocmd + `vim.defer_fn`. This ensures the cursor is positioned after diffview's async `set_file` completes (which resets cursor to line 1 on `file_open_new`).
176
188
  - **Socket auto-discovery**: When `NVIM_SOCKET` is not set, the tool scans `$TMPDIR/nvim.$USER/` and `/tmp` for Neovim socket files, verifies each is live, and uses `lsof` to match the Neovim process's working directory against the current project. This allows zero-configuration usage in ad-hoc terminals — just run `nvim` and OpenCode will find it.
177
189
 
178
190
  ### Review workflow instructions
@@ -197,10 +209,6 @@ Show surrounding code context around the current hunk. Useful when the agent or
197
209
 
198
210
  Allow the user to accept or reject individual hunks from the diff view, similar to `git add -p`. This would integrate with diffview.nvim's staging capabilities.
199
211
 
200
- ### Logical ordering
201
-
202
- Instead of the agent deciding order ad-hoc, build smarter ordering heuristics — e.g., analyzing import graphs to automatically determine dependency order between changed files.
203
-
204
212
  ### OpenCode session diff integration
205
213
 
206
214
  Instead of using `git diff` to determine changed files, use OpenCode's `/session/:id/diff` API endpoint to get exactly which files the agent modified in the current session. This would avoid showing unrelated uncommitted changes.
@@ -270,7 +270,9 @@ function M.on_view_opened(view)
270
270
  end
271
271
 
272
272
  --- Number of context lines to show above and below a focused hunk.
273
- local HUNK_CONTEXT = 3
273
+ --- This provides enough surrounding code to understand the change without
274
+ --- overwhelming the view with unrelated code.
275
+ local HUNK_CONTEXT = 5
274
276
 
275
277
  --- Apply a pending cursor position and hunk focus after diffview has finished
276
278
  --- loading a file. Called from the DiffviewDiffBufWinEnter autocmd and from
@@ -372,6 +374,20 @@ function M._apply_hunk_focus(view, hunk)
372
374
  vim.wo.foldmethod = "manual"
373
375
  vim.wo.foldenable = true
374
376
 
377
+ -- Show absolute line numbers so the user can correlate with the
378
+ -- hunk header line ranges (e.g. @@ -273,1 +273,3 @@)
379
+ vim.wo.number = true
380
+ vim.wo.relativenumber = false
381
+
382
+ -- Override the Folded highlight in this window so fold lines don't
383
+ -- look like diff modifications. Uses winhl to scope it to this window.
384
+ local existing_winhl = vim.wo.winhl or ""
385
+ if not existing_winhl:match("Folded:") then
386
+ vim.wo.winhl = existing_winhl
387
+ .. (existing_winhl ~= "" and "," or "")
388
+ .. "Folded:DiffviewDiffFoldedReview"
389
+ end
390
+
375
391
  -- Remove all existing folds
376
392
  pcall(vim.cmd, "normal! zE")
377
393
 
@@ -437,6 +453,11 @@ function M.setup(opts)
437
453
  _G.DiffviewHunks = DiffviewHunks
438
454
  _G.DiffviewGoTo = DiffviewGoTo
439
455
 
456
+ -- Define a neutral highlight for fold lines in hunk-focus mode.
457
+ -- Links to Comment by default so folds look like muted separators
458
+ -- rather than diff modifications. Users can override this.
459
+ vim.api.nvim_set_hl(0, "DiffviewDiffFoldedReview", { link = "Comment", default = true })
460
+
440
461
  -- Listen for diffview's DiffviewDiffBufWinEnter autocmd to apply pending
441
462
  -- cursor positions after async file loading completes.
442
463
  vim.api.nvim_create_autocmd("User", {
@@ -120,7 +120,8 @@ const statusLabel = (status: string | undefined): string =>
120
120
  const formatHunkPosition = (): string => {
121
121
  if (reviewQueue.length === 0) return "No review in progress."
122
122
  const item = reviewQueue[reviewPosition]
123
- return `Reviewing: ${item.file} (${statusLabel(item.status)}) ${item.header} — item ${reviewPosition + 1} of ${reviewQueue.length}.`
123
+ const fileCount = new Set(reviewQueue.map(h => h.file)).size
124
+ return `Reviewing: ${item.file} (${statusLabel(item.status)}) ${item.header} — item ${reviewPosition + 1} of ${reviewQueue.length} across ${fileCount} file${fileCount === 1 ? "" : "s"}.`
124
125
  }
125
126
 
126
127
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-nvim-diff-review",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Agent-driven guided code review for Neovim + OpenCode",
5
5
  "main": "opencode-plugin/index.ts",
6
6
  "keywords": [