Skip to content

fix(ui_select): align upstream opts.preview_items spec#2722

Merged
phanen merged 1 commit into
mainfrom
preview_items
May 9, 2026
Merged

fix(ui_select): align upstream opts.preview_items spec#2722
phanen merged 1 commit into
mainfrom
preview_items

Conversation

@phanen
Copy link
Copy Markdown
Collaborator

@phanen phanen commented May 9, 2026

#2533 (comment)

Summary by CodeRabbit

  • Refactor

    • Previewer now immediately displays available temporary scratch buffers, improving preview responsiveness and avoiding redundant buffer updates.
    • Selection preview integration normalizes returned preview info and supplies sensible defaults for missing position data, improving cursor and position behavior.
  • Chores

    • Public types updated to optionally track scratch-buffer references used by the previewer.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 579aed63-4a31-4fdc-84e8-01da0f355211

📥 Commits

Reviewing files that changed from the base of the PR and between 4438e2d and 464e3d6.

📒 Files selected for processing (3)
  • lua/fzf-lua/previewer/builtin.lua
  • lua/fzf-lua/providers/ui_select.lua
  • lua/fzf-lua/types.lua
✅ Files skipped from review due to trivial changes (1)
  • lua/fzf-lua/types.lua
🚧 Files skipped from review as they are similar to previous changes (2)
  • lua/fzf-lua/previewer/builtin.lua
  • lua/fzf-lua/providers/ui_select.lua

📝 Walkthrough

Walkthrough

Adds an optional _scratch_buf Entry field, normalizes ui_select preview_item outputs into that shape, and makes the built-in previewer prefer entry._scratch_buf when populating preview buffers.

Changes

Preview Buffer Entry Enhancement

Layer / File(s) Summary
Data Shape
lua/fzf-lua/types.lua
Entry type extends with optional _scratch_buf?: integer field for unmanaged scratch buffers.
Preview Item Integration
lua/fzf-lua/providers/ui_select.lua
previewer:parse_entry wraps ui_opts.preview_item result, mapping res.buf/res.pos/res.pos_end into _scratch_buf, line, col, end_line, end_col with defaults of 1.
Buffer Selection Logic
lua/fzf-lua/previewer/builtin.lua
populate_preview_buf now checks entry._scratch_buf and, if present, sets preview lines from it and returns before cached/temp buffer selection.

Sequence Diagram(s)

sequenceDiagram
  participant UI as ui_select
  participant PreviewItem as preview_item
  participant Previewer as builtin_previewer
  participant Buffer as buffer
  UI->>PreviewItem: preview_item(entry_str, cb)
  PreviewItem-->>Previewer: res { buf, pos, pos_end }
  Previewer->>Buffer: use res.buf as _scratch_buf
  Previewer->>Previewer: _set_preview_lines(entry._scratch_buf)
  Previewer-->>UI: preview_buf_post(entry)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ibhagwan

Poem

🐰 I found a tiny scratch of light,
A buffer tucked away just right.
I hop and glue the pieces true,
Preview now shows what I knew.
Hooray — the view is snug and bright! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: updating ui_select to align with upstream opts.preview_items specification.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch preview_items

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
lua/fzf-lua/providers/ui_select.lua (1)

187-193: ⚡ Quick win

Consider improving default fallback for missing position data.

When pos_end is missing, the code defaults end_line and end_col to 1, which may not accurately represent the intended selection range. A more typical pattern would be to default the end position to match the start position when not explicitly provided.

♻️ Proposed improvement
 function previewer:parse_entry(entry_str, cb)
   local res = ui_opts.preview_item(entry_str, cb)
+  if not res then
+    return {}
+  end
   local pos_start, pos_end = res.pos, res.pos_end
+  local start_line = pos_start and pos_start[1] or 1
+  local start_col = pos_start and pos_start[2] or 1
   return {
     _scratch_buf = res.buf,
-    line = pos_start and pos_start[1] or 1,
-    col = pos_start and pos_start[2] or 1,
-    end_line = pos_end and pos_end[1] or 1,
-    end_col = pos_end and pos_end[2] or 1,
+    line = start_line,
+    col = start_col,
+    end_line = pos_end and pos_end[1] or start_line,
+    end_col = pos_end and pos_end[2] or start_col,
   }
 end
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lua/fzf-lua/providers/ui_select.lua` around lines 187 - 193, The returned
position table currently falls back to 1 for end_line and end_col when pos_end
is nil; change this to default end_line/end_col to the start position instead:
use pos_start[1] and pos_start[2] as the fallback for end_line and end_col
(refer to pos_start, pos_end and the returned keys _scratch_buf, line, col,
end_line, end_col) so missing end positions mirror the start position.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lua/fzf-lua/providers/ui_select.lua`:
- Around line 184-194: The previewer:parse_entry implementation assumes
ui_opts.preview_item returns a table; add nil / malformed result validation
after calling ui_opts.preview_item(entry_str, cb) to guard against runtime
errors by checking that res is a table and contains expected fields (res.buf,
res.pos, res.pos_end); if res is nil or missing fields, return a safe fallback
object (e.g., _scratch_buf = nil, line/col/end_line/end_col = 1) or normalize
missing pos/pos_end to default {1,1} before accessing res.pos[1] etc., so
previewer:parse_entry never dereferences nil.

---

Nitpick comments:
In `@lua/fzf-lua/providers/ui_select.lua`:
- Around line 187-193: The returned position table currently falls back to 1 for
end_line and end_col when pos_end is nil; change this to default
end_line/end_col to the start position instead: use pos_start[1] and
pos_start[2] as the fallback for end_line and end_col (refer to pos_start,
pos_end and the returned keys _scratch_buf, line, col, end_line, end_col) so
missing end positions mirror the start position.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 33cbde40-fe9c-4791-a7a0-969daa518047

📥 Commits

Reviewing files that changed from the base of the PR and between 33fe4b6 and 0cf7e82.

📒 Files selected for processing (3)
  • lua/fzf-lua/previewer/builtin.lua
  • lua/fzf-lua/providers/ui_select.lua
  • lua/fzf-lua/types.lua

Comment thread lua/fzf-lua/providers/ui_select.lua
@phanen phanen merged commit 375078d into main May 9, 2026
10 checks passed
@phanen phanen mentioned this pull request May 9, 2026
@ibhagwan
Copy link
Copy Markdown
Owner

ibhagwan commented May 9, 2026

Ty @phanen !

@neo451
Copy link
Copy Markdown

neo451 commented May 9, 2026

ty @phanen for the quick implementation, but I think there's one last part missing, the idea of preview_item should be same as format_item, it should have no special processing of the item, just pass in the full shape of an individual item in the list.

@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented May 9, 2026

ty @phanen, it should have no special processing of the item, just pass in the full shape of an individual item in the list.

I didn't get what's your meaning. Could you show me an example?

@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented May 9, 2026

Oh, I see, you mean don't apply format_item

@phanen
Copy link
Copy Markdown
Collaborator Author

phanen commented May 9, 2026

fixed in 44816af

@neo451
Copy link
Copy Markdown

neo451 commented May 9, 2026

brilliant! thank you for your work! @phanen

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