chore(watchers): refactor events and make debouncer safe
- fs poll -> fs events - make debouncer safe and fix diagnostics events
This commit is contained in:
committed by
GitHub
parent
26512c369f
commit
06e48c29c4
@@ -90,43 +90,45 @@ function M.update()
|
||||
if not M.enable or not core.get_explorer() or not view.is_buf_valid(view.get_bufnr()) then
|
||||
return
|
||||
end
|
||||
local ps = log.profile_start "diagnostics update"
|
||||
log.line("diagnostics", "update")
|
||||
utils.debounce("diagnostics", M.debounce_delay, function()
|
||||
local ps = log.profile_start "diagnostics update"
|
||||
log.line("diagnostics", "update")
|
||||
|
||||
local buffer_severity
|
||||
if is_using_coc() then
|
||||
buffer_severity = from_coc()
|
||||
else
|
||||
buffer_severity = from_nvim_lsp()
|
||||
end
|
||||
local buffer_severity
|
||||
if is_using_coc() then
|
||||
buffer_severity = from_coc()
|
||||
else
|
||||
buffer_severity = from_nvim_lsp()
|
||||
end
|
||||
|
||||
M.clear()
|
||||
M.clear()
|
||||
|
||||
local nodes_by_line = utils.get_nodes_by_line(core.get_explorer().nodes, core.get_nodes_starting_line())
|
||||
for _, node in pairs(nodes_by_line) do
|
||||
node.diag_status = nil
|
||||
end
|
||||
local nodes_by_line = utils.get_nodes_by_line(core.get_explorer().nodes, core.get_nodes_starting_line())
|
||||
for _, node in pairs(nodes_by_line) do
|
||||
node.diag_status = nil
|
||||
end
|
||||
|
||||
for bufname, severity in pairs(buffer_severity) do
|
||||
local bufpath = utils.canonical_path(bufname)
|
||||
log.line("diagnostics", " bufpath '%s' severity %d", bufpath, severity)
|
||||
if 0 < severity and severity < 5 then
|
||||
for line, node in pairs(nodes_by_line) do
|
||||
local nodepath = utils.canonical_path(node.absolute_path)
|
||||
log.line("diagnostics", " %d checking nodepath '%s'", line, nodepath)
|
||||
if M.show_on_dirs and vim.startswith(bufpath, nodepath) then
|
||||
log.line("diagnostics", " matched fold node '%s'", node.absolute_path)
|
||||
node.diag_status = severity
|
||||
add_sign(line, severity)
|
||||
elseif nodepath == bufpath then
|
||||
log.line("diagnostics", " matched file node '%s'", node.absolute_path)
|
||||
node.diag_status = severity
|
||||
add_sign(line, severity)
|
||||
for bufname, severity in pairs(buffer_severity) do
|
||||
local bufpath = utils.canonical_path(bufname)
|
||||
log.line("diagnostics", " bufpath '%s' severity %d", bufpath, severity)
|
||||
if 0 < severity and severity < 5 then
|
||||
for line, node in pairs(nodes_by_line) do
|
||||
local nodepath = utils.canonical_path(node.absolute_path)
|
||||
log.line("diagnostics", " %d checking nodepath '%s'", line, nodepath)
|
||||
if M.show_on_dirs and vim.startswith(bufpath, nodepath) then
|
||||
log.line("diagnostics", " matched fold node '%s'", node.absolute_path)
|
||||
node.diag_status = severity
|
||||
add_sign(line, severity)
|
||||
elseif nodepath == bufpath then
|
||||
log.line("diagnostics", " matched file node '%s'", node.absolute_path)
|
||||
node.diag_status = severity
|
||||
add_sign(line, severity)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
log.profile_end(ps, "diagnostics update")
|
||||
log.profile_end(ps, "diagnostics update")
|
||||
end)
|
||||
end
|
||||
|
||||
local links = {
|
||||
@@ -138,6 +140,7 @@ local links = {
|
||||
|
||||
function M.setup(opts)
|
||||
M.enable = opts.diagnostics.enable
|
||||
M.debounce_delay = opts.diagnostics.debounce_delay
|
||||
|
||||
if M.enable then
|
||||
log.line("diagnostics", "setup")
|
||||
|
||||
Reference in New Issue
Block a user