Skip to content

Commit

Permalink
Merge branch 'master' into chore-undefined-field
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis authored Nov 2, 2024
2 parents 1e1a273 + 82ab19e commit 3b68b94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
8 changes: 7 additions & 1 deletion lua/nvim-tree/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ function M.update()
end
end
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()
if explorer then
explorer.renderer:draw()
Expand Down
25 changes: 11 additions & 14 deletions lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ local tabinitial = {
}

local BUFNR_PER_TAB = {}

---@type { name: string, value: any }[]
local BUFFER_OPTIONS = {
swapfile = false,
buftype = "nofile",
modifiable = false,
filetype = "NvimTree",
bufhidden = "wipe",
buflisted = false,
{ name = "bufhidden", value = "wipe" },
{ name = "buflisted", value = false },
{ name = "buftype", value = "nofile" },
{ name = "filetype", value = "NvimTree" },
{ name = "modifiable", value = false },
{ name = "swapfile", value = false },
}

---@param bufnr integer
Expand Down Expand Up @@ -101,8 +103,9 @@ local function create_buffer(bufnr)
BUFNR_PER_TAB[tab] = bufnr or vim.api.nvim_create_buf(false, false)
vim.api.nvim_buf_set_name(M.get_bufnr(), "NvimTree_" .. tab)

for option, value in pairs(BUFFER_OPTIONS) do
vim.bo[M.get_bufnr()][option] = value
bufnr = M.get_bufnr()
for _, option in ipairs(BUFFER_OPTIONS) do
vim.api.nvim_set_option_value(option.name, option.value, { buf = bufnr })
end

require("nvim-tree.keymap").on_attach(M.get_bufnr())
Expand Down Expand Up @@ -515,12 +518,6 @@ function M.get_bufnr()
return BUFNR_PER_TAB[vim.api.nvim_get_current_tabpage()]
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()
local view_winnr = M.get_winnr()
local view_bufnr = M.get_bufnr()
Expand Down

0 comments on commit 3b68b94

Please sign in to comment.