fix: Handle window switching
The outline window is sometimes not refreshed when switching windows. This is fixed by listening for `BufEnter` events. A debouncing function is also added to prevent spamming the language server.
This commit is contained in:
@@ -20,7 +20,7 @@ end
|
|||||||
|
|
||||||
local function setup_global_autocmd()
|
local function setup_global_autocmd()
|
||||||
vim.cmd(
|
vim.cmd(
|
||||||
"au InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost * :lua require('symbols-outline')._refresh()")
|
"au InsertLeave,WinEnter,BufEnter,BufWinEnter,TabEnter,BufWritePost * :lua require('symbols-outline')._refresh()")
|
||||||
vim.cmd "au BufLeave * lua require'symbols-outline'._prevent_buffer_override()"
|
vim.cmd "au BufLeave * lua require'symbols-outline'._prevent_buffer_override()"
|
||||||
if config.options.auto_preview then
|
if config.options.auto_preview then
|
||||||
vim.cmd "au WinEnter * lua require'symbols-outline.preview'.close_if_not_in_outline()"
|
vim.cmd "au WinEnter * lua require'symbols-outline.preview'.close_if_not_in_outline()"
|
||||||
@@ -42,6 +42,23 @@ local function getParams()
|
|||||||
return {textDocument = vim.lsp.util.make_text_document_params()}
|
return {textDocument = vim.lsp.util.make_text_document_params()}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- @param f function
|
||||||
|
--- @param delay number
|
||||||
|
--- @return function
|
||||||
|
local function debounce(f, delay)
|
||||||
|
local timer = vim.loop.new_timer()
|
||||||
|
|
||||||
|
return function (...)
|
||||||
|
local args = { ... }
|
||||||
|
|
||||||
|
timer:start(delay, 0, vim.schedule_wrap(function ()
|
||||||
|
timer:stop()
|
||||||
|
f(unpack(args))
|
||||||
|
end))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
-- STATE
|
-- STATE
|
||||||
-------------------------
|
-------------------------
|
||||||
@@ -57,7 +74,7 @@ local function wipe_state()
|
|||||||
M.state = {outline_items = {}, flattened_outline_items = {}}
|
M.state = {outline_items = {}, flattened_outline_items = {}}
|
||||||
end
|
end
|
||||||
|
|
||||||
function M._refresh()
|
local function __refresh ()
|
||||||
if M.state.outline_buf ~= nil then
|
if M.state.outline_buf ~= nil then
|
||||||
local function refresh_handler(response)
|
local function refresh_handler(response)
|
||||||
if response == nil or type(response) ~= 'table' then
|
if response == nil or type(response) ~= 'table' then
|
||||||
@@ -88,6 +105,8 @@ function M._refresh()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M._refresh = debounce(__refresh, 100)
|
||||||
|
|
||||||
function M._goto_location(change_focus)
|
function M._goto_location(change_focus)
|
||||||
local current_line = vim.api.nvim_win_get_cursor(M.state.outline_win)[1]
|
local current_line = vim.api.nvim_win_get_cursor(M.state.outline_win)[1]
|
||||||
local node = M.state.flattened_outline_items[current_line]
|
local node = M.state.flattened_outline_items[current_line]
|
||||||
|
|||||||
Reference in New Issue
Block a user