fix(#2954): resolve occasional tree flashing on diagnostics, set tree buffer options in deterministic order (#2980)
* fix(#2954): set buffer options in deterministic order This ensures related autocmd's (e.g. on FileType) will be called in a similar environment. * fix(#2954): redraw only for diagnostics if source buffer is 'buflisted' is_buf_valid has been inlined since it is only used for diagnostics and its name is misleading.
This commit is contained in:
parent
120ba58254
commit
82ab19ebf7
@ -165,7 +165,13 @@ function M.update()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
log.profile_end(profile)
|
log.profile_end(profile)
|
||||||
if view.is_buf_valid(view.get_bufnr()) then
|
|
||||||
|
local bufnr = view.get_bufnr()
|
||||||
|
local should_draw = bufnr
|
||||||
|
and vim.api.nvim_buf_is_valid(bufnr)
|
||||||
|
and vim.api.nvim_buf_is_loaded(bufnr)
|
||||||
|
and vim.api.nvim_get_option_value("buflisted", { buf = bufnr })
|
||||||
|
if should_draw then
|
||||||
local explorer = core.get_explorer()
|
local explorer = core.get_explorer()
|
||||||
if explorer then
|
if explorer then
|
||||||
explorer.renderer:draw()
|
explorer.renderer:draw()
|
||||||
|
|||||||
@ -65,13 +65,15 @@ local tabinitial = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local BUFNR_PER_TAB = {}
|
local BUFNR_PER_TAB = {}
|
||||||
|
|
||||||
|
---@type { name: string, value: any }[]
|
||||||
local BUFFER_OPTIONS = {
|
local BUFFER_OPTIONS = {
|
||||||
swapfile = false,
|
{ name = "bufhidden", value = "wipe" },
|
||||||
buftype = "nofile",
|
{ name = "buflisted", value = false },
|
||||||
modifiable = false,
|
{ name = "buftype", value = "nofile" },
|
||||||
filetype = "NvimTree",
|
{ name = "filetype", value = "NvimTree" },
|
||||||
bufhidden = "wipe",
|
{ name = "modifiable", value = false },
|
||||||
buflisted = false,
|
{ name = "swapfile", value = false },
|
||||||
}
|
}
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
@ -101,8 +103,9 @@ local function create_buffer(bufnr)
|
|||||||
BUFNR_PER_TAB[tab] = bufnr or vim.api.nvim_create_buf(false, false)
|
BUFNR_PER_TAB[tab] = bufnr or vim.api.nvim_create_buf(false, false)
|
||||||
vim.api.nvim_buf_set_name(M.get_bufnr(), "NvimTree_" .. tab)
|
vim.api.nvim_buf_set_name(M.get_bufnr(), "NvimTree_" .. tab)
|
||||||
|
|
||||||
for option, value in pairs(BUFFER_OPTIONS) do
|
bufnr = M.get_bufnr()
|
||||||
vim.bo[M.get_bufnr()][option] = value
|
for _, option in ipairs(BUFFER_OPTIONS) do
|
||||||
|
vim.api.nvim_set_option_value(option.name, option.value, { buf = bufnr })
|
||||||
end
|
end
|
||||||
|
|
||||||
require("nvim-tree.keymap").on_attach(M.get_bufnr())
|
require("nvim-tree.keymap").on_attach(M.get_bufnr())
|
||||||
@ -497,12 +500,6 @@ function M.get_bufnr()
|
|||||||
return BUFNR_PER_TAB[vim.api.nvim_get_current_tabpage()]
|
return BUFNR_PER_TAB[vim.api.nvim_get_current_tabpage()]
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr number
|
|
||||||
---@return boolean
|
|
||||||
function M.is_buf_valid(bufnr)
|
|
||||||
return bufnr and vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_is_loaded(bufnr)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M._prevent_buffer_override()
|
function M._prevent_buffer_override()
|
||||||
local view_winnr = M.get_winnr()
|
local view_winnr = M.get_winnr()
|
||||||
local view_bufnr = M.get_bufnr()
|
local view_bufnr = M.get_bufnr()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user