Skip to content

Commit

Permalink
diagnostic: generate count early before preview
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed May 20, 2024
1 parent ad61778 commit f07c10e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
12 changes: 3 additions & 9 deletions lua/lspsaga/codeaction/preview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ local api, lsp = vim.api, vim.lsp
local config = require('lspsaga').config
local win = require('lspsaga.window')
local util = require('lspsaga.util')
local act = require('lspsaga.codeaction')

local function get_action_diff(main_buf, tuple)
if not tuple then
if not tuple or not tuple[2] then
return
end
local act = require('lspsaga.codeaction')
local action = tuple[2]
if not action then
return
end

local id = tuple[1]
local id, action = unpack(tuple)
local client = lsp.get_client_by_id(id)
if not action.edit and client and act:support_resolve(client) then
action = act:get_resolve_action(client, action, main_buf)
Expand All @@ -22,7 +17,6 @@ local function get_action_diff(main_buf, tuple)
end
tuple[2] = action
end

if not action.edit then
return
end
Expand Down
13 changes: 6 additions & 7 deletions lua/lspsaga/diagnostic/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,10 @@ function diag:get_diagnostic(opt)
return vim.diagnostic.get()
end

function diag:code_action_cb(action_tuples, enriched_ctx, counts)
local win_conf = api.nvim_win_get_config(self.float_winid)
win_conf.title = gen_float_title(counts)
api.nvim_win_set_config(self.float_winid, win_conf)
function diag:code_action_cb(action_tuples, enriched_ctx, win_conf)
local contents = {
util.gen_truncate_line(win_conf.width),
}

for index, client_with_actions in pairs(action_tuples) do
if #client_with_actions ~= 2 then
vim.notify('[lspsaga] failed indexing client actions')
Expand Down Expand Up @@ -255,7 +251,7 @@ function diag:goto_pos(pos, opts)
if not entry then
return
end
(is_forward and vim.diagnostic.goto_next or vim.diagnostic.goto_prev)(vim.tbl_extend("keep", {
(is_forward and vim.diagnostic.goto_next or vim.diagnostic.goto_prev)(vim.tbl_extend('keep', {
float = {
border = config.ui.border,
header = '',
Expand Down Expand Up @@ -285,6 +281,9 @@ function diag:goto_pos(pos, opts)
end
local curbuf = api.nvim_get_current_buf()
local diagnostics, counts = self:get_cursor_diagnostic()
local win_conf = api.nvim_win_get_config(self.float_winid)
win_conf.title = gen_float_title(counts)
api.nvim_win_set_config(self.float_winid, win_conf)
act:send_request(curbuf, {
context = { diagnostics = diagnostics },
range = {
Expand All @@ -298,7 +297,7 @@ function diag:goto_pos(pos, opts)
end
vim.bo[self.float_bufnr].modifiable = true
self.main_buf = curbuf
self:code_action_cb(action_tuples, enriched_ctx, counts)
self:code_action_cb(action_tuples, enriched_ctx, win_conf)
vim.bo[self.float_bufnr].modifiable = false
end)
end)
Expand Down

0 comments on commit f07c10e

Please sign in to comment.