From f3f66ae560c39cdfd5e4fde613b2cec5f8d34a12 Mon Sep 17 00:00:00 2001 From: Harivansh Rathi Date: Sat, 28 Mar 2026 21:23:59 -0400 Subject: [PATCH] Fix fzf-lua ansi_from_hl compatibility Wrap the highlighted segment render path so forge only consumes the first return value from fzf-lua's ansi_from_hl helper, and add a regression spec covering the newer two-value return shape. Co-authored-by: Codex --- lua/forge/picker/fzf.lua | 2 +- spec/fzf_picker_spec.lua | 51 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 spec/fzf_picker_spec.lua diff --git a/lua/forge/picker/fzf.lua b/lua/forge/picker/fzf.lua index d4d3a05..f7f4ed2 100644 --- a/lua/forge/picker/fzf.lua +++ b/lua/forge/picker/fzf.lua @@ -23,7 +23,7 @@ local function render(segments) local parts = {} for _, seg in ipairs(segments) do if seg[2] then - table.insert(parts, utils.ansi_from_hl(seg[2], seg[1])) + table.insert(parts, (utils.ansi_from_hl(seg[2], seg[1]))) else table.insert(parts, seg[1]) end diff --git a/spec/fzf_picker_spec.lua b/spec/fzf_picker_spec.lua new file mode 100644 index 0000000..bf1a1a7 --- /dev/null +++ b/spec/fzf_picker_spec.lua @@ -0,0 +1,51 @@ +vim.opt.runtimepath:prepend(vim.fn.getcwd()) + +package.preload['fzf-lua.utils'] = function() + return { + ansi_from_hl = function(_, text) + return text, '\27[38;2;1;2;3m' + end, + } +end + +local captured + +package.preload['fzf-lua'] = function() + return { + fzf_exec = function(lines, opts) + captured = { lines = lines, opts = opts } + end, + } +end + +describe('fzf picker', function() + before_each(function() + captured = nil + package.loaded['forge'] = nil + package.loaded['forge.picker.fzf'] = nil + vim.g.forge = nil + end) + + it('renders highlighted segments when ansi_from_hl returns extra values', function() + local picker = require('forge.picker.fzf') + picker.pick({ + prompt = 'PRs> ', + entries = { + { + display = { + { '#42', 'ForgeNumber' }, + { ' fix api drift ' }, + { 'alice 1h', 'ForgeDim' }, + }, + value = '42', + }, + }, + actions = {}, + picker_name = 'pr', + }) + + assert.is_not_nil(captured) + assert.same({ '1\t#42 fix api drift alice 1h' }, captured.lines) + assert.equals('PRs> ', captured.opts.prompt) + end) +end)