From 9062f761726ff35f779f44912111f97470a77285 Mon Sep 17 00:00:00 2001 From: chomosuke Date: Tue, 29 Nov 2022 17:41:05 +1100 Subject: [PATCH 1/3] Filtered dir with git status that are open when show_on_open_dir is false --- lua/nvim-tree/actions/init.lua | 1 + lua/nvim-tree/actions/moves/item.lua | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index f42875f92ed..9d3a3bb9961 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -395,6 +395,7 @@ function M.setup(opts) require("nvim-tree.actions.fs.remove-file").setup(opts) require("nvim-tree.actions.fs.copy-paste").setup(opts) require("nvim-tree.actions.tree-modifiers.expand-all").setup(opts) + require("nvim-tree.actions.moves.item").setup(opts) cleanup_existing_mappings() diff --git a/lua/nvim-tree/actions/moves/item.lua b/lua/nvim-tree/actions/moves/item.lua index 3eb74b807a2..4a58c7c1c7d 100644 --- a/lua/nvim-tree/actions/moves/item.lua +++ b/lua/nvim-tree/actions/moves/item.lua @@ -14,7 +14,7 @@ function M.fn(where, what) for line, node in pairs(nodes_by_line) do local valid = false if what == "git" then - valid = node.git_status ~= nil + valid = node.git_status ~= nil and (not node.open or M.show_on_open_dirs) elseif what == "diag" then valid = node.diag_status ~= nil end @@ -52,4 +52,8 @@ function M.fn(where, what) end end +function M.setup(opts) + M.show_on_open_dirs = opts.git.show_on_open_dirs +end + return M From c13093d2a6213f783f15729636c8506e069db699 Mon Sep 17 00:00:00 2001 From: chomosuke Date: Tue, 29 Nov 2022 18:08:09 +1100 Subject: [PATCH 2/3] refactored for single source of truth of existence of git status on a node Putting `has_git_status()` in `explorer.common` because that's where node.status is constructed Or at least I think that's where it's constructed --- lua/nvim-tree/actions/init.lua | 1 - lua/nvim-tree/actions/moves/item.lua | 7 ++----- lua/nvim-tree/explorer/common.lua | 20 +++++++++++++++++--- lua/nvim-tree/renderer/components/git.lua | 11 ++++------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index 9d3a3bb9961..f42875f92ed 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -395,7 +395,6 @@ function M.setup(opts) require("nvim-tree.actions.fs.remove-file").setup(opts) require("nvim-tree.actions.fs.copy-paste").setup(opts) require("nvim-tree.actions.tree-modifiers.expand-all").setup(opts) - require("nvim-tree.actions.moves.item").setup(opts) cleanup_existing_mappings() diff --git a/lua/nvim-tree/actions/moves/item.lua b/lua/nvim-tree/actions/moves/item.lua index 4a58c7c1c7d..b5ab12d17ba 100644 --- a/lua/nvim-tree/actions/moves/item.lua +++ b/lua/nvim-tree/actions/moves/item.lua @@ -2,6 +2,7 @@ local utils = require "nvim-tree.utils" local view = require "nvim-tree.view" local core = require "nvim-tree.core" local lib = require "nvim-tree.lib" +local explorer_common = require "nvim-tree.explorer.common" local M = {} @@ -14,7 +15,7 @@ function M.fn(where, what) for line, node in pairs(nodes_by_line) do local valid = false if what == "git" then - valid = node.git_status ~= nil and (not node.open or M.show_on_open_dirs) + valid = explorer_common.has_git_status(node) elseif what == "diag" then valid = node.diag_status ~= nil end @@ -52,8 +53,4 @@ function M.fn(where, what) end end -function M.setup(opts) - M.show_on_open_dirs = opts.git.show_on_open_dirs -end - return M diff --git a/lua/nvim-tree/explorer/common.lua b/lua/nvim-tree/explorer/common.lua index c3bed863e1a..75a28e86a34 100644 --- a/lua/nvim-tree/explorer/common.lua +++ b/lua/nvim-tree/explorer/common.lua @@ -10,9 +10,7 @@ local function get_dir_git_status(parent_ignored, status, absolute_path) return file_status end - if M.config.git.show_on_dirs then - return status.dirs and status.dirs[absolute_path] - end + return status.dirs and status.dirs[absolute_path] end local function get_git_status(parent_ignored, status, absolute_path) @@ -41,6 +39,22 @@ function M.update_git_status(node, parent_ignored, status) end end +function M.has_git_status(node) + if not node.git_status then + -- status doesn't exist + return false + elseif not node.nodes then + -- status exist and is a file + return true + elseif not node.open then + -- status exist, is a closed dir + return M.config.git.show_on_dirs + else + -- status exist, is a open dir + return M.config.git.show_on_dirs and M.config.git.show_on_open_dirs + end +end + function M.node_destroy(node) if not node then return diff --git a/lua/nvim-tree/renderer/components/git.lua b/lua/nvim-tree/renderer/components/git.lua index 7b82d92ed4e..91a86a33317 100644 --- a/lua/nvim-tree/renderer/components/git.lua +++ b/lua/nvim-tree/renderer/components/git.lua @@ -1,4 +1,5 @@ local notify = require "nvim-tree.notify" +local explorer_common = require "nvim-tree.explorer.common" local M = { SIGN_GROUP = "NvimTreeGitSigns", @@ -75,16 +76,12 @@ local function warn_status(git_status) ) end -local function show_git(node) - return node.git_status and (not node.open or M.git_show_on_open_dirs) -end - local function get_icons_(node) - local git_status = node.git_status - if not show_git(node) then + if not explorer_common.has_git_status(node) then return nil end + local git_status = node.git_status local icons = M.git_icons[git_status] if not icons then if not M.config.highlight_git then @@ -141,7 +138,7 @@ end local function get_highlight_(node) local git_status = node.git_status - if not show_git(node) then + if not explorer_common.has_git_status(node) then return end From bb5ce0aa8be57b3e21f36c94ff8c02f1d73703de Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 3 Dec 2022 14:31:00 +1100 Subject: [PATCH 3/3] 1786 semantic nit --- lua/nvim-tree/actions/moves/item.lua | 2 +- lua/nvim-tree/explorer/common.lua | 2 +- lua/nvim-tree/renderer/components/git.lua | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/nvim-tree/actions/moves/item.lua b/lua/nvim-tree/actions/moves/item.lua index b5ab12d17ba..b5646193346 100644 --- a/lua/nvim-tree/actions/moves/item.lua +++ b/lua/nvim-tree/actions/moves/item.lua @@ -15,7 +15,7 @@ function M.fn(where, what) for line, node in pairs(nodes_by_line) do local valid = false if what == "git" then - valid = explorer_common.has_git_status(node) + valid = explorer_common.shows_git_status(node) elseif what == "diag" then valid = node.diag_status ~= nil end diff --git a/lua/nvim-tree/explorer/common.lua b/lua/nvim-tree/explorer/common.lua index 75a28e86a34..71eae8af608 100644 --- a/lua/nvim-tree/explorer/common.lua +++ b/lua/nvim-tree/explorer/common.lua @@ -39,7 +39,7 @@ function M.update_git_status(node, parent_ignored, status) end end -function M.has_git_status(node) +function M.shows_git_status(node) if not node.git_status then -- status doesn't exist return false diff --git a/lua/nvim-tree/renderer/components/git.lua b/lua/nvim-tree/renderer/components/git.lua index 91a86a33317..fae22803f30 100644 --- a/lua/nvim-tree/renderer/components/git.lua +++ b/lua/nvim-tree/renderer/components/git.lua @@ -77,7 +77,7 @@ local function warn_status(git_status) end local function get_icons_(node) - if not explorer_common.has_git_status(node) then + if not explorer_common.shows_git_status(node) then return nil end @@ -138,7 +138,7 @@ end local function get_highlight_(node) local git_status = node.git_status - if not explorer_common.has_git_status(node) then + if not explorer_common.shows_git_status(node) then return end