Skip to content

Commit

Permalink
[fix]: when switch buffer too quickly, lightbulb's windows is not cor…
Browse files Browse the repository at this point in the history
…rect
  • Loading branch information
jinzhongjia committed Feb 7, 2024
1 parent 29d540a commit f122f3d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lua/LspUI/lightbulb/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ end

-- this function will request all lsp clients
--- @param buffer_id integer buffer's id
--- @param window_id integer window's id
--- @param callback function callback is a function, has a param boolean
M.request = function(buffer_id, callback)
M.request = function(buffer_id, window_id, callback)
-- this buffer id maybe invalid
if not api.nvim_buf_is_valid(buffer_id) then
return
end
local params = lsp.util.make_range_params()
local params = lsp.util.make_range_params(window_id)
local context = {
triggerKind = vim.lsp.protocol.CodeActionTriggerKind.Invoked,
diagnostics = lib_lsp.diagnostic_vim_to_lsp(
Expand Down Expand Up @@ -126,7 +127,8 @@ M.request = function(buffer_id, callback)
if err ~= nil then
lib_notify.Warn(
string.format(
"lightbulb meet error, server %s, error code is %d, msg is %s",
"lightbulb meet error, current buffer is %d, server %s, error code is %d, msg is %s",
buffer_id,
client.name,
err.code,
err.message
Expand All @@ -150,9 +152,9 @@ M.request = function(buffer_id, callback)
end
end

local debounce_func = function(buffer_id)
local debounce_func = function(buffer_id, window_id)
local func = function()
M.request(buffer_id, function(result)
M.request(buffer_id, window_id, function(result)
M.clear_render()
if result then
local line = fn.line(".")
Expand Down Expand Up @@ -189,14 +191,15 @@ M.autocmd = function()
callback = function()
-- get current buffer
local current_buffer = api.nvim_get_current_buf()
local current_window = api.nvim_get_current_win()
local group_id = api.nvim_create_augroup(
"Lspui_lightBulb_" .. tostring(current_buffer),
{ clear = true }
)

autocmd_list[current_buffer] = {}

local new_func = debounce_func(current_buffer)
local new_func = debounce_func(current_buffer, current_window)

local hold_autocmd_id = api.nvim_create_autocmd({ "CursorHold" }, {
group = group_id,
Expand Down

0 comments on commit f122f3d

Please sign in to comment.