From 7629d4d1069cad1fc88b39d11162b88a13b10b27 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 18 Apr 2022 23:39:51 +1000 Subject: [PATCH] #1091 diagnostics logging (#1170) --- README.md | 1 + doc/nvim-tree-lua.txt | 1 + lua/nvim-tree.lua | 1 + lua/nvim-tree/diagnostics.lua | 16 ++++++++++++++-- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a3b39a2f..7aba0171 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS all = false, config = false, copy_paste = false, + diagnostics = false, git = false, profile = false, }, diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index a64760a1..de9411d8 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -185,6 +185,7 @@ function. all = false, config = false, copy_paste = false, + diagnostics = false, git = false, profile = false, }, diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index fd34be0f..13416761 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -410,6 +410,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS all = false, config = false, copy_paste = false, + diagnostics = false, git = false, profile = false, }, diff --git a/lua/nvim-tree/diagnostics.lua b/lua/nvim-tree/diagnostics.lua index 6b92c5e0..64f93516 100644 --- a/lua/nvim-tree/diagnostics.lua +++ b/lua/nvim-tree/diagnostics.lua @@ -2,6 +2,7 @@ local a = vim.api local utils = require "nvim-tree.utils" local view = require "nvim-tree.view" local core = require "nvim-tree.core" +local log = require "nvim-tree.log" local M = {} @@ -124,6 +125,9 @@ 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") + local buffer_severity if is_using_coc() then buffer_severity = from_coc() @@ -133,19 +137,25 @@ function M.update() M.clear() 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 local node, line = utils.find_node(core.get_explorer().nodes, function(node) + local nodepath = utils.canonical_path(node.absolute_path) + log.line("diagnostics", " checking nodepath '%s'", nodepath) if M.show_on_dirs and not node.open then - return vim.startswith(bufname, node.absolute_path) + return vim.startswith(bufpath, nodepath) else - return node.absolute_path == bufname + return nodepath == bufpath end end) if node then + log.line("diagnostics", " matched node '%s'", node.absolute_path) add_sign(line, severity) end end end + log.profile_end(ps, "diagnostics update") end local has_06 = vim.fn.has "nvim-0.6" == 1 @@ -170,8 +180,10 @@ function M.setup(opts) if M.enable then if has_06 then + log.line("diagnostics", "setup has_06") vim.cmd "au DiagnosticChanged * lua require'nvim-tree.diagnostics'.update()" else + log.line("diagnostics", "setup not has_06") vim.cmd "au User LspDiagnosticsChanged lua require'nvim-tree.diagnostics'.update()" end end