Skip to content

Commit bc4a26d

Browse files
committed
Assign diagnostic version per node to reduce overhead
Signed-off-by: iusmac <[email protected]>
1 parent 2baf3da commit bc4a26d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lua/nvim-tree/diagnostics.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ local severity_levels = {
1515
---@type table
1616
local buffer_severity_dict = {}
1717

18+
--- The cache version number of the buffer-severity mappings.
19+
---@type integer
20+
local BUFFER_SEVERITY_VERSION = 0
21+
1822
---@param path string
1923
---@return string
2024
local function uniformize_path(path)
@@ -91,6 +95,7 @@ function M.update()
9195
else
9296
buffer_severity_dict = from_nvim_lsp()
9397
end
98+
BUFFER_SEVERITY_VERSION = BUFFER_SEVERITY_VERSION + 1
9499
log.node("diagnostics", buffer_severity_dict, "update")
95100
log.profile_end(profile)
96101
if view.is_buf_valid(view.get_bufnr()) then
@@ -101,7 +106,7 @@ end
101106

102107
---@param node Node
103108
function M.update_node_severity_level(node)
104-
if not M.enable then
109+
if not M.enable or node.diag_status_version == BUFFER_SEVERITY_VERSION then
105110
return
106111
end
107112

@@ -127,6 +132,7 @@ function M.update_node_severity_level(node)
127132
else
128133
node.diag_status = buffer_severity_dict[nodepath]
129134
end
135+
node.diag_status_version = BUFFER_SEVERITY_VERSION
130136
end
131137

132138
function M.setup(opts)

lua/nvim-tree/node.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
---@field type string
1919
---@field watcher function|nil
2020
---@field diag_status integer|nil
21+
---@field diag_status_version integer|nil
2122

2223
---@class DirNode: BaseNode
2324
---@field has_children boolean

0 commit comments

Comments
 (0)