Skip to content

Commit

Permalink
fix(codeaction preview): update internal items list with resolve results
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Bellows authored and ibhagwan committed Feb 28, 2024
1 parent b697e26 commit 2cbe90d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lua/fzf-lua/previewer/codeaction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ local function diff_tuple(err, tuple, diff_opts)
end

-- https://github.com/neovim/neovim/blob/v0.9.4/runtime/lua/vim/lsp/buf.lua#L666
local function preview_action_tuple(tuple, diff_opts, callback)
local function preview_action_tuple(self, tuple, idx, callback)
-- neovim changed the ui.select params with 0.10.0 (#947)
-- { client_id, action } ==> { ctx = <LSP context>, action = <action> }
if tuple.ctx then
Expand All @@ -157,29 +157,34 @@ local function preview_action_tuple(tuple, diff_opts, callback)
then
local function on_result(diff_callback, err, resolved_action)
if err then
return diff_callback(err, tuple, diff_opts)
return diff_callback(err, tuple, self.diff_opts)
else
return diff_callback(err, { tuple[1], resolved_action }, diff_opts)
return diff_callback(err, { tuple[1], resolved_action }, self.diff_opts)
end
end
local function update_internal_items(resolved_action)
self.opts._items[idx] = { tuple[1], resolved_action }
end

if callback then
client.request("codeAction/resolve", action, function(err, resolved_action)
update_internal_items(resolved_action)
on_result(callback, err, resolved_action)
end)
return { string.format("Resolving action (%s)...", action.kind) }
else
local res = client.request_sync("codeAction/resolve", action)
local err, resolved_action = res and res.err, res and res.result
update_internal_items(resolved_action)
if type(err) == "table" or type(resolved_action) == "table" then
return on_result(diff_tuple, err, resolved_action)
else
-- display the default "unsupported" message
return diff_tuple(nil, tuple, diff_opts)
return diff_tuple(nil, tuple, self.diff_opts)
end
end
else
return diff_tuple(nil, tuple, diff_opts)
return diff_tuple(nil, tuple, self.diff_opts)
end
end

Expand Down Expand Up @@ -208,7 +213,7 @@ function M.builtin:populate_preview_buf(entry_str)
local idx = tonumber(entry_str:match("^%d+%."))
assert(type(idx) == "number")
local tuple = self.opts._items[idx]
local lines = preview_action_tuple(tuple, self.diff_opts,
local lines = preview_action_tuple(self, tuple, idx,
-- use the async version for "codeAction/resolve"
function(err, resolved_tuple)
if vim.api.nvim_buf_is_valid(self.tmpbuf) then
Expand Down Expand Up @@ -244,7 +249,7 @@ function M.native:cmdline(o)
local idx = tonumber(entries[1]:match("^%d+%."))
assert(type(idx) == "number")
local tuple = self.opts._items[idx]
local lines = preview_action_tuple(tuple, self.diff_opts)
local lines = preview_action_tuple(self, tuple, idx)
return table.concat(lines, "\r\n")
end, "{}", self.opts.debug)
if self.pager and #self.pager > 0 and vim.fn.executable(self.pager:match("[^%s]+")) == 1 then
Expand Down

0 comments on commit 2cbe90d

Please sign in to comment.