fix(ui_select): align upstream opts.preview_items spec#2722
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds an optional ChangesPreview Buffer Entry Enhancement
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
lua/fzf-lua/providers/ui_select.lua (1)
187-193: ⚡ Quick winConsider improving default fallback for missing position data.
When
pos_endis missing, the code defaultsend_lineandend_colto1, 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
📒 Files selected for processing (3)
lua/fzf-lua/previewer/builtin.lualua/fzf-lua/providers/ui_select.lualua/fzf-lua/types.lua
|
Ty @phanen ! |
|
ty @phanen for the quick implementation, but I think there's one last part missing, the idea of |
I didn't get what's your meaning. Could you show me an example? |
|
Oh, I see, you mean don't apply |
|
fixed in 44816af |
|
brilliant! thank you for your work! @phanen |
#2533 (comment)
Summary by CodeRabbit
Refactor
Chores