From 80d4f2838353915cc1567f3547d535276af9ab4c Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 3 Jul 2022 16:04:49 +1000 Subject: [PATCH] feat(#1245): add next_diag_item and prev_diag_item actions --- .luarc.json | 6 +++++- doc/nvim-tree-lua.txt | 4 ++++ lua/nvim-tree/actions/init.lua | 16 ++++++++++++++-- lua/nvim-tree/actions/movements.lua | 13 ++++++++++--- lua/nvim-tree/diagnostics.lua | 9 ++++++++- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/.luarc.json b/.luarc.json index 2314c4a6..173b5845 100644 --- a/.luarc.json +++ b/.luarc.json @@ -6,9 +6,13 @@ "vim" ], "disable": [ + "cast-local-type", "lowercase-global", "missing-parameter", - "trailing-space" + "missing-return", + "missing-return-value", + "need-check-nil", + "param-type-mismatch" ] } } diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 5a12ca46..cb6d1485 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -984,7 +984,9 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings `y` copy_name copy name to system clipboard `Y` copy_path copy relative path to system clipboard `gy` copy_absolute_path copy absolute path to system clipboard +`[e` prev_diag_item go to next diagnostic item `[c` prev_git_item go to next git item +`]e` next_diag_item go to prev diagnostic item `]c` next_git_item go to prev git item `-` dir_up navigate up to the parent directory of the current file/directory `s` system_open open a file with default system application or a folder with default file manager, using |system_open| option @@ -1029,7 +1031,9 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings { key = "y", action = "copy_name" } { key = "Y", action = "copy_path" } { key = "gy", action = "copy_absolute_path" } + { key = "[e", action = "prev_diag_item" } { key = "[c", action = "prev_git_item" } + { key = "]e", action = "next_diag_item" } { key = "]c", action = "next_git_item" } { key = "-", action = "dir_up" } { key = "s", action = "system_open" } diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index 40da651d..73747b78 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -153,11 +153,21 @@ local DEFAULT_MAPPINGS = { action = "copy_absolute_path", desc = "copy absolute path to system clipboard", }, + { + key = "[e", + action = "prev_diag_item", + desc = "go to next diagnostic item", + }, { key = "[c", action = "prev_git_item", desc = "go to next git item", }, + { + key = "]e", + action = "next_diag_item", + desc = "go to prev diagnostic item", + }, { key = "]c", action = "next_git_item", @@ -243,11 +253,13 @@ local keypress_funcs = { last_sibling = require("nvim-tree.actions.movements").sibling(math.huge), live_filter = require("nvim-tree.live-filter").start_filtering, clear_live_filter = require("nvim-tree.live-filter").clear_filter, - next_git_item = require("nvim-tree.actions.movements").find_git_item "next", + next_diag_item = require("nvim-tree.actions.movements").find_item("next", "diag"), + next_git_item = require("nvim-tree.actions.movements").find_item("next", "git"), next_sibling = require("nvim-tree.actions.movements").sibling(1), parent_node = require("nvim-tree.actions.movements").parent_node(false), paste = require("nvim-tree.actions.copy-paste").paste, - prev_git_item = require("nvim-tree.actions.movements").find_git_item "prev", + prev_diag_item = require("nvim-tree.actions.movements").find_item("prev", "diag"), + prev_git_item = require("nvim-tree.actions.movements").find_item("prev", "git"), prev_sibling = require("nvim-tree.actions.movements").sibling(-1), refresh = require("nvim-tree.actions.reloaders").reload_explorer, remove = require("nvim-tree.actions.remove-file").fn, diff --git a/lua/nvim-tree/actions/movements.lua b/lua/nvim-tree/actions/movements.lua index 25a19146..2a768d40 100644 --- a/lua/nvim-tree/actions/movements.lua +++ b/lua/nvim-tree/actions/movements.lua @@ -84,20 +84,27 @@ function M.sibling(direction) end end -function M.find_git_item(where) +function M.find_item(where, what) return function() local node_cur = lib.get_node_at_cursor() local nodes_by_line = utils.get_nodes_by_line(core.get_explorer().nodes, core.get_nodes_starting_line()) local cur, first, prev, nex = nil, nil, nil, nil for line, node in pairs(nodes_by_line) do - if not first and node.git_status then + local valid = false + if what == "git" then + valid = node.git_status ~= nil + elseif what == "diag" then + valid = node.diag_status ~= nil + end + + if not first and valid then first = line end if node == node_cur then cur = line - elseif node.git_status then + elseif valid then if not cur then prev = line end diff --git a/lua/nvim-tree/diagnostics.lua b/lua/nvim-tree/diagnostics.lua index ecaed103..f2360570 100644 --- a/lua/nvim-tree/diagnostics.lua +++ b/lua/nvim-tree/diagnostics.lua @@ -101,19 +101,26 @@ function M.update() end 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 + 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 nodes_by_line = utils.get_nodes_by_line(core.get_explorer().nodes, core.get_nodes_starting_line()) 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