explorer/common.lua -> explorer/node.lua
This commit is contained in:
@@ -2,7 +2,7 @@ local utils = require "nvim-tree.utils"
|
|||||||
local view = require "nvim-tree.view"
|
local view = require "nvim-tree.view"
|
||||||
local core = require "nvim-tree.core"
|
local core = require "nvim-tree.core"
|
||||||
local lib = require "nvim-tree.lib"
|
local lib = require "nvim-tree.lib"
|
||||||
local explorer_common = require "nvim-tree.explorer.common"
|
local explorer_node = require "nvim-tree.explorer.node"
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ function M.fn(where, what)
|
|||||||
for line, node in pairs(nodes_by_line) do
|
for line, node in pairs(nodes_by_line) do
|
||||||
local valid = false
|
local valid = false
|
||||||
if what == "git" then
|
if what == "git" then
|
||||||
valid = explorer_common.get_git_status(node) ~= nil
|
valid = explorer_node.get_git_status(node) ~= nil
|
||||||
elseif what == "diag" then
|
elseif what == "diag" then
|
||||||
valid = node.diag_status ~= nil
|
valid = node.diag_status ~= nil
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ local view = require "nvim-tree.view"
|
|||||||
local renderer = require "nvim-tree.renderer"
|
local renderer = require "nvim-tree.renderer"
|
||||||
local explorer_module = require "nvim-tree.explorer"
|
local explorer_module = require "nvim-tree.explorer"
|
||||||
local core = require "nvim-tree.core"
|
local core = require "nvim-tree.core"
|
||||||
local explorer_common = require "nvim-tree.explorer.common"
|
local explorer_node = require "nvim-tree.explorer.node"
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ function M.reload_node_status(parent_node, projects)
|
|||||||
local project_root = git.get_project_root(parent_node.absolute_path)
|
local project_root = git.get_project_root(parent_node.absolute_path)
|
||||||
local status = projects[project_root] or {}
|
local status = projects[project_root] or {}
|
||||||
for _, node in ipairs(parent_node.nodes) do
|
for _, node in ipairs(parent_node.nodes) do
|
||||||
explorer_common.update_git_status(node, explorer_common.is_git_ignored(parent_node), status)
|
explorer_node.update_git_status(node, explorer_node.is_git_ignored(parent_node), status)
|
||||||
if node.nodes and #node.nodes > 0 then
|
if node.nodes and #node.nodes > 0 then
|
||||||
M.reload_node_status(node, projects)
|
M.reload_node_status(node, projects)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local utils = require "nvim-tree.utils"
|
local utils = require "nvim-tree.utils"
|
||||||
local builders = require "nvim-tree.explorer.node-builders"
|
local builders = require "nvim-tree.explorer.node-builders"
|
||||||
local common = require "nvim-tree.explorer.common"
|
local explorer_node = require "nvim-tree.explorer.node"
|
||||||
local sorters = require "nvim-tree.explorer.sorters"
|
local sorters = require "nvim-tree.explorer.sorters"
|
||||||
local filters = require "nvim-tree.explorer.filters"
|
local filters = require "nvim-tree.explorer.filters"
|
||||||
local live_filter = require "nvim-tree.live-filter"
|
local live_filter = require "nvim-tree.live-filter"
|
||||||
@@ -13,7 +13,7 @@ local function get_type_from(type_, cwd)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function populate_children(handle, cwd, node, git_status)
|
local function populate_children(handle, cwd, node, git_status)
|
||||||
local node_ignored = common.is_git_ignored(node)
|
local node_ignored = explorer_node.is_git_ignored(node)
|
||||||
local nodes_by_path = utils.bool_record(node.nodes, "absolute_path")
|
local nodes_by_path = utils.bool_record(node.nodes, "absolute_path")
|
||||||
local filter_status = filters.prepare(git_status)
|
local filter_status = filters.prepare(git_status)
|
||||||
while true do
|
while true do
|
||||||
@@ -39,7 +39,7 @@ local function populate_children(handle, cwd, node, git_status)
|
|||||||
if child then
|
if child then
|
||||||
table.insert(node.nodes, child)
|
table.insert(node.nodes, child)
|
||||||
nodes_by_path[child.absolute_path] = true
|
nodes_by_path[child.absolute_path] = true
|
||||||
common.update_git_status(child, node_ignored, git_status)
|
explorer_node.update_git_status(child, node_ignored, git_status)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -64,7 +64,7 @@ function M.explore(node, status)
|
|||||||
populate_children(handle, cwd, node, status)
|
populate_children(handle, cwd, node, status)
|
||||||
|
|
||||||
local is_root = not node.parent
|
local is_root = not node.parent
|
||||||
local child_folder_only = common.has_one_child_folder(node) and node.nodes[1]
|
local child_folder_only = explorer_node.has_one_child_folder(node) and node.nodes[1]
|
||||||
if M.config.group_empty and not is_root and child_folder_only then
|
if M.config.group_empty and not is_root and child_folder_only then
|
||||||
node.group_next = child_folder_only
|
node.group_next = child_folder_only
|
||||||
local ns = M.explore(child_folder_only, status)
|
local ns = M.explore(child_folder_only, status)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local git = require "nvim-tree.git"
|
local git = require "nvim-tree.git"
|
||||||
local watch = require "nvim-tree.explorer.watch"
|
local watch = require "nvim-tree.explorer.watch"
|
||||||
local common = require "nvim-tree.explorer.common"
|
local explorer_node = require "nvim-tree.explorer.node"
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ end
|
|||||||
|
|
||||||
function Explorer:destroy()
|
function Explorer:destroy()
|
||||||
local function iterate(node)
|
local function iterate(node)
|
||||||
common.node_destroy(node)
|
explorer_node.node_destroy(node)
|
||||||
if node.nodes then
|
if node.nodes then
|
||||||
for _, child in pairs(node.nodes) do
|
for _, child in pairs(node.nodes) do
|
||||||
iterate(child)
|
iterate(child)
|
||||||
@@ -45,7 +45,7 @@ function Explorer:destroy()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
require("nvim-tree.explorer.common").setup(opts)
|
require("nvim-tree.explorer.node").setup(opts)
|
||||||
require("nvim-tree.explorer.explore").setup(opts)
|
require("nvim-tree.explorer.explore").setup(opts)
|
||||||
require("nvim-tree.explorer.filters").setup(opts)
|
require("nvim-tree.explorer.filters").setup(opts)
|
||||||
require("nvim-tree.explorer.sorters").setup(opts)
|
require("nvim-tree.explorer.sorters").setup(opts)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local utils = require "nvim-tree.utils"
|
local utils = require "nvim-tree.utils"
|
||||||
local builders = require "nvim-tree.explorer.node-builders"
|
local builders = require "nvim-tree.explorer.node-builders"
|
||||||
local common = require "nvim-tree.explorer.common"
|
local explorer_node = require "nvim-tree.explorer.node"
|
||||||
local filters = require "nvim-tree.explorer.filters"
|
local filters = require "nvim-tree.explorer.filters"
|
||||||
local sorters = require "nvim-tree.explorer.sorters"
|
local sorters = require "nvim-tree.explorer.sorters"
|
||||||
local live_filter = require "nvim-tree.live-filter"
|
local live_filter = require "nvim-tree.live-filter"
|
||||||
@@ -15,7 +15,7 @@ local M = {}
|
|||||||
local function update_status(nodes_by_path, node_ignored, status)
|
local function update_status(nodes_by_path, node_ignored, status)
|
||||||
return function(node)
|
return function(node)
|
||||||
if nodes_by_path[node.absolute_path] then
|
if nodes_by_path[node.absolute_path] then
|
||||||
common.update_git_status(node, node_ignored, status)
|
explorer_node.update_git_status(node, node_ignored, status)
|
||||||
end
|
end
|
||||||
return node
|
return node
|
||||||
end
|
end
|
||||||
@@ -29,7 +29,7 @@ end
|
|||||||
|
|
||||||
local function update_parent_statuses(node, project, root)
|
local function update_parent_statuses(node, project, root)
|
||||||
while project and node and node.absolute_path ~= root do
|
while project and node and node.absolute_path ~= root do
|
||||||
common.update_git_status(node, false, project)
|
explorer_node.update_git_status(node, false, project)
|
||||||
node = node.parent
|
node = node.parent
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -53,7 +53,7 @@ function M.reload(node, git_status, unloaded_bufnr)
|
|||||||
|
|
||||||
local child_names = {}
|
local child_names = {}
|
||||||
|
|
||||||
local node_ignored = common.is_git_ignored(node)
|
local node_ignored = explorer_node.is_git_ignored(node)
|
||||||
local nodes_by_path = utils.key_by(node.nodes, "absolute_path")
|
local nodes_by_path = utils.key_by(node.nodes, "absolute_path")
|
||||||
while true do
|
while true do
|
||||||
local ok, name, t = pcall(vim.loop.fs_scandir_next, handle)
|
local ok, name, t = pcall(vim.loop.fs_scandir_next, handle)
|
||||||
@@ -82,7 +82,7 @@ function M.reload(node, git_status, unloaded_bufnr)
|
|||||||
|
|
||||||
if n.type ~= t then
|
if n.type ~= t then
|
||||||
utils.array_remove(node.nodes, n)
|
utils.array_remove(node.nodes, n)
|
||||||
common.node_destroy(n)
|
explorer_node.node_destroy(n)
|
||||||
nodes_by_path[abs] = nil
|
nodes_by_path[abs] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -119,14 +119,14 @@ function M.reload(node, git_status, unloaded_bufnr)
|
|||||||
if child_names[n.absolute_path] then
|
if child_names[n.absolute_path] then
|
||||||
return child_names[n.absolute_path]
|
return child_names[n.absolute_path]
|
||||||
else
|
else
|
||||||
common.node_destroy(n)
|
explorer_node.node_destroy(n)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end, node.nodes)
|
end, node.nodes)
|
||||||
)
|
)
|
||||||
|
|
||||||
local is_root = not node.parent
|
local is_root = not node.parent
|
||||||
local child_folder_only = common.has_one_child_folder(node) and node.nodes[1]
|
local child_folder_only = explorer_node.has_one_child_folder(node) and node.nodes[1]
|
||||||
if M.config.group_empty and not is_root and child_folder_only then
|
if M.config.group_empty and not is_root and child_folder_only then
|
||||||
node.group_next = child_folder_only
|
node.group_next = child_folder_only
|
||||||
local ns = M.reload(child_folder_only, git_status)
|
local ns = M.reload(child_folder_only, git_status)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ local git_utils = require "nvim-tree.git.utils"
|
|||||||
local Runner = require "nvim-tree.git.runner"
|
local Runner = require "nvim-tree.git.runner"
|
||||||
local Watcher = require("nvim-tree.watcher").Watcher
|
local Watcher = require("nvim-tree.watcher").Watcher
|
||||||
local Iterator = require "nvim-tree.iterators.node-iterator"
|
local Iterator = require "nvim-tree.iterators.node-iterator"
|
||||||
local explorer_common = require "nvim-tree.explorer.common"
|
local explorer_node = require "nvim-tree.explorer.node"
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
config = {},
|
config = {},
|
||||||
@@ -109,8 +109,8 @@ local function reload_tree_at(project_root)
|
|||||||
Iterator.builder(root_node.nodes)
|
Iterator.builder(root_node.nodes)
|
||||||
:hidden()
|
:hidden()
|
||||||
:applier(function(node)
|
:applier(function(node)
|
||||||
local parent_ignored = explorer_common.is_git_ignored(node.parent)
|
local parent_ignored = explorer_node.is_git_ignored(node.parent)
|
||||||
explorer_common.update_git_status(node, parent_ignored, git_status)
|
explorer_node.update_git_status(node, parent_ignored, git_status)
|
||||||
end)
|
end)
|
||||||
:recursor(function(node)
|
:recursor(function(node)
|
||||||
return node.nodes and #node.nodes > 0 and node.nodes
|
return node.nodes and #node.nodes > 0 and node.nodes
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
local notify = require "nvim-tree.notify"
|
local notify = require "nvim-tree.notify"
|
||||||
local explorer_common = require "nvim-tree.explorer.common"
|
local explorer_node = require "nvim-tree.explorer.node"
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
SIGN_GROUP = "NvimTreeGitSigns",
|
SIGN_GROUP = "NvimTreeGitSigns",
|
||||||
@@ -60,7 +60,7 @@ local function warn_status(git_status)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_icons_(node)
|
local function get_icons_(node)
|
||||||
local git_status = explorer_common.get_git_status(node)
|
local git_status = explorer_node.get_git_status(node)
|
||||||
if git_status == nil then
|
if git_status == nil then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -132,7 +132,7 @@ function M.setup_signs(i)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_highlight_(node)
|
local function get_highlight_(node)
|
||||||
local git_status = explorer_common.get_git_status(node)
|
local git_status = explorer_node.get_git_status(node)
|
||||||
if git_status == nil then
|
if git_status == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user