This commit is contained in:
Alexander Courtis 2024-11-08 18:18:51 +11:00
parent f2dd8a4397
commit ddd28ecd01
15 changed files with 114 additions and 113 deletions

View File

@ -30,11 +30,11 @@ function Filters:new(args)
self.enabled = self.explorer.opts.filters.enable self.enabled = self.explorer.opts.filters.enable
self.states = { self.states = {
custom = true, custom = true,
dotfiles = self.explorer.opts.filters.dotfiles, dotfiles = self.explorer.opts.filters.dotfiles,
git_ignored = self.explorer.opts.filters.git_ignored, git_ignored = self.explorer.opts.filters.git_ignored,
git_clean = self.explorer.opts.filters.git_clean, git_clean = self.explorer.opts.filters.git_clean,
no_buffer = self.explorer.opts.filters.no_buffer, no_buffer = self.explorer.opts.filters.no_buffer,
no_bookmark = self.explorer.opts.filters.no_bookmark, no_bookmark = self.explorer.opts.filters.no_bookmark,
} }

View File

@ -200,10 +200,10 @@ function Explorer:reload(node, project)
-- To reset we must 'zero' everything that we use -- To reset we must 'zero' everything that we use
node.hidden_stats = vim.tbl_deep_extend("force", node.hidden_stats or {}, { node.hidden_stats = vim.tbl_deep_extend("force", node.hidden_stats or {}, {
git = 0, git = 0,
buf = 0, buf = 0,
dotfile = 0, dotfile = 0,
custom = 0, custom = 0,
bookmark = 0, bookmark = 0,
}) })
@ -234,11 +234,11 @@ function Explorer:reload(node, project)
if not nodes_by_path[abs] then if not nodes_by_path[abs] then
local new_child = node_factory.create({ local new_child = node_factory.create({
explorer = self, explorer = self,
parent = node, parent = node,
absolute_path = abs, absolute_path = abs,
name = name, name = name,
fs_stat = stat fs_stat = stat
}) })
if new_child then if new_child then
table.insert(node.nodes, new_child) table.insert(node.nodes, new_child)
@ -355,10 +355,10 @@ function Explorer:populate_children(handle, cwd, node, project, parent)
local filter_status = parent.filters:prepare(project) local filter_status = parent.filters:prepare(project)
node.hidden_stats = vim.tbl_deep_extend("force", node.hidden_stats or {}, { node.hidden_stats = vim.tbl_deep_extend("force", node.hidden_stats or {}, {
git = 0, git = 0,
buf = 0, buf = 0,
dotfile = 0, dotfile = 0,
custom = 0, custom = 0,
bookmark = 0, bookmark = 0,
}) })
@ -378,11 +378,11 @@ function Explorer:populate_children(handle, cwd, node, project, parent)
local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status) local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status)
if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] then if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] then
local child = node_factory.create({ local child = node_factory.create({
explorer = self, explorer = self,
parent = node, parent = node,
absolute_path = abs, absolute_path = abs,
name = name, name = name,
fs_stat = stat fs_stat = stat
}) })
if child then if child then
table.insert(node.nodes, child) table.insert(node.nodes, child)

View File

@ -169,21 +169,21 @@ local function create_overlay(self)
if view.View.float.enable then if view.View.float.enable then
-- don't close nvim-tree float when focus is changed to filter window -- don't close nvim-tree float when focus is changed to filter window
vim.api.nvim_clear_autocmds({ vim.api.nvim_clear_autocmds({
event = "WinLeave", event = "WinLeave",
pattern = "NvimTree_*", pattern = "NvimTree_*",
group = vim.api.nvim_create_augroup("NvimTree", { clear = false }), group = vim.api.nvim_create_augroup("NvimTree", { clear = false }),
}) })
end end
configure_buffer_overlay(self) configure_buffer_overlay(self)
overlay_winnr = vim.api.nvim_open_win(overlay_bufnr, true, { overlay_winnr = vim.api.nvim_open_win(overlay_bufnr, true, {
col = 1, col = 1,
row = 0, row = 0,
relative = "cursor", relative = "cursor",
width = calculate_overlay_win_width(self), width = calculate_overlay_win_width(self),
height = 1, height = 1,
border = "none", border = "none",
style = "minimal", style = "minimal",
}) })
if vim.fn.has("nvim-0.10") == 1 then if vim.fn.has("nvim-0.10") == 1 then

View File

@ -138,12 +138,12 @@ function Sorter:sort(t)
for _, n in ipairs(t) do for _, n in ipairs(t) do
table.insert(t_user, { table.insert(t_user, {
absolute_path = n.absolute_path, absolute_path = n.absolute_path,
executable = n.executable, executable = n.executable,
extension = n.extension, extension = n.extension,
filetype = vim.filetype.match({ filename = n.name }), filetype = vim.filetype.match({ filename = n.name }),
link_to = n.link_to, link_to = n.link_to,
name = n.name, name = n.name,
type = n.type, type = n.type,
}) })
table.insert(origin_index, n) table.insert(origin_index, n)
end end

View File

@ -130,11 +130,11 @@ function M.reload_project(toplevel, path, callback)
---@type GitRunnerArgs ---@type GitRunnerArgs
local args = { local args = {
toplevel = toplevel, toplevel = toplevel,
path = path, path = path,
list_untracked = git_utils.should_show_untracked(toplevel), list_untracked = git_utils.should_show_untracked(toplevel),
list_ignored = true, list_ignored = true,
timeout = M.config.git.timeout, timeout = M.config.git.timeout,
} }
if callback then if callback then
@ -276,10 +276,10 @@ function M.load_project(path)
end end
local path_xys = GitRunner:run({ local path_xys = GitRunner:run({
toplevel = toplevel, toplevel = toplevel,
list_untracked = git_utils.should_show_untracked(toplevel), list_untracked = git_utils.should_show_untracked(toplevel),
list_ignored = true, list_ignored = true,
timeout = M.config.git.timeout, timeout = M.config.git.timeout,
}) })
local watcher = nil local watcher = nil
@ -299,10 +299,10 @@ function M.load_project(path)
local git_dir = vim.env.GIT_DIR or M._git_dirs_by_toplevel[toplevel] or utils.path_join({ toplevel, ".git" }) local git_dir = vim.env.GIT_DIR or M._git_dirs_by_toplevel[toplevel] or utils.path_join({ toplevel, ".git" })
watcher = Watcher:create({ watcher = Watcher:create({
path = git_dir, path = git_dir,
files = WATCHED_FILES, files = WATCHED_FILES,
callback = callback, callback = callback,
data = { data = {
toplevel = toplevel, toplevel = toplevel,
} }
}) })
@ -310,8 +310,8 @@ function M.load_project(path)
if path_xys then if path_xys then
M._projects_by_toplevel[toplevel] = { M._projects_by_toplevel[toplevel] = {
files = path_xys, files = path_xys,
dirs = git_utils.project_files_to_project_dirs(path_xys, toplevel), dirs = git_utils.project_files_to_project_dirs(path_xys, toplevel),
watcher = watcher, watcher = watcher,
} }
return M._projects_by_toplevel[toplevel] return M._projects_by_toplevel[toplevel]

View File

@ -94,8 +94,8 @@ function GitRunner:get_spawn_options(stdout_handle, stderr_handle)
local untracked = self.args.list_untracked and "-u" or nil local untracked = self.args.list_untracked and "-u" or nil
local ignored = (self.args.list_untracked and self.args.list_ignored) and "--ignored=matching" or "--ignored=no" local ignored = (self.args.list_untracked and self.args.list_ignored) and "--ignored=matching" or "--ignored=no"
return { return {
args = { "--no-optional-locks", "status", "--porcelain=v1", "-z", ignored, untracked, self.args.path }, args = { "--no-optional-locks", "status", "--porcelain=v1", "-z", ignored, untracked, self.args.path },
cwd = self.args.toplevel, cwd = self.args.toplevel,
stdio = { nil, stdout_handle, stderr_handle }, stdio = { nil, stdout_handle, stderr_handle },
} }
end end

View File

@ -172,8 +172,8 @@ function M.git_status_dir(parent_ignored, project, path, path_fallback)
elseif project then elseif project then
ns = { ns = {
file = project.files and (project.files[path] or project.files[path_fallback]), file = project.files and (project.files[path] or project.files[path_fallback]),
dir = project.dirs and { dir = project.dirs and {
direct = project.dirs.direct and project.dirs.direct[path], direct = project.dirs.direct and project.dirs.direct[path],
indirect = project.dirs.indirect and project.dirs.indirect[path], indirect = project.dirs.indirect and project.dirs.indirect[path],
}, },
} }

View File

@ -48,10 +48,10 @@ function DirectoryLinkNode:highlighted_icon()
if self.open then if self.open then
str = self.explorer.opts.renderer.icons.glyphs.folder.symlink_open str = self.explorer.opts.renderer.icons.glyphs.folder.symlink_open
hl = "NvimTreeOpenedFolderIcon" hl = "NvimTreeOpenedFolderIcon"
else else
str = self.explorer.opts.renderer.icons.glyphs.folder.symlink str = self.explorer.opts.renderer.icons.glyphs.folder.symlink
hl = "NvimTreeClosedFolderIcon" hl = "NvimTreeClosedFolderIcon"
end end
return { str = str, hl = { hl } } return { str = str, hl = { hl } }
@ -64,8 +64,9 @@ function DirectoryLinkNode:highlighted_name()
if self.explorer.opts.renderer.symlink_destination then if self.explorer.opts.renderer.symlink_destination then
local link_to = utils.path_relative(self.link_to, self.explorer.absolute_path) local link_to = utils.path_relative(self.link_to, self.explorer.absolute_path)
name.str = string.format("%s%s%s", name.str, self.explorer.opts.renderer.icons.symlink_arrow, link_to)
name.hl = { "NvimTreeSymlinkFolderName" } name.str = string.format("%s%s%s", name.str, self.explorer.opts.renderer.icons.symlink_arrow, link_to)
name.hl = { "NvimTreeSymlinkFolderName" }
end end
return name return name

View File

@ -273,12 +273,12 @@ end
---Create a sanitized partial copy of a node, populating children recursively. ---Create a sanitized partial copy of a node, populating children recursively.
---@return DirectoryNode cloned ---@return DirectoryNode cloned
function DirectoryNode:clone() function DirectoryNode:clone()
local clone = Node.clone(self) --[[@as DirectoryNode]] local clone = Node.clone(self) --[[@as DirectoryNode]]
clone.has_children = self.has_children clone.has_children = self.has_children
clone.group_next = nil clone.group_next = nil
clone.nodes = {} clone.nodes = {}
clone.open = self.open clone.open = self.open
clone.hidden_stats = nil clone.hidden_stats = nil
for _, child in ipairs(self.nodes) do for _, child in ipairs(self.nodes) do

View File

@ -125,17 +125,17 @@ function Node:clone()
---@type Node ---@type Node
local clone = { local clone = {
type = self.type, type = self.type,
explorer = explorer_placeholder, explorer = explorer_placeholder,
absolute_path = self.absolute_path, absolute_path = self.absolute_path,
executable = self.executable, executable = self.executable,
fs_stat = self.fs_stat, fs_stat = self.fs_stat,
git_status = self.git_status, git_status = self.git_status,
hidden = self.hidden, hidden = self.hidden,
name = self.name, name = self.name,
parent = nil, parent = nil,
diag_status = nil, diag_status = nil,
is_dot = self.is_dot, is_dot = self.is_dot,
} }
return clone return clone

View File

@ -408,11 +408,11 @@ function Builder:setup_hidden_display_function(opts)
-- In case of missing field such as live_filter we zero it, otherwise keep field as is -- In case of missing field such as live_filter we zero it, otherwise keep field as is
hidden_stats = vim.tbl_deep_extend("force", { hidden_stats = vim.tbl_deep_extend("force", {
live_filter = 0, live_filter = 0,
git = 0, git = 0,
buf = 0, buf = 0,
dotfile = 0, dotfile = 0,
custom = 0, custom = 0,
bookmark = 0, bookmark = 0,
}, hidden_stats or {}) }, hidden_stats or {})
local ok, result = pcall(hidden_display, hidden_stats) local ok, result = pcall(hidden_display, hidden_stats)

View File

@ -57,13 +57,13 @@ local function show()
end end
M.popup_win = vim.api.nvim_open_win(vim.api.nvim_create_buf(false, false), false, { M.popup_win = vim.api.nvim_open_win(vim.api.nvim_create_buf(false, false), false, {
relative = "win", relative = "win",
row = 0, row = 0,
bufpos = { vim.api.nvim_win_get_cursor(0)[1] - 1, 0 }, bufpos = { vim.api.nvim_win_get_cursor(0)[1] - 1, 0 },
width = math.min(text_width, vim.o.columns - 2), width = math.min(text_width, vim.o.columns - 2),
height = 1, height = 1,
noautocmd = true, noautocmd = true,
style = "minimal", style = "minimal",
}) })
local ns_id = vim.api.nvim_get_namespaces()["NvimTreeHighlights"] local ns_id = vim.api.nvim_get_namespaces()["NvimTreeHighlights"]

View File

@ -52,14 +52,14 @@ end
---@param glyphs GitGlyphsByStatus ---@param glyphs GitGlyphsByStatus
function DecoratorGit:build_icons_by_status(glyphs) function DecoratorGit:build_icons_by_status(glyphs)
self.icons_by_status = {} self.icons_by_status = {}
self.icons_by_status.staged = { str = glyphs.staged, hl = { "NvimTreeGitStagedIcon" }, ord = 1 } self.icons_by_status.staged = { str = glyphs.staged, hl = { "NvimTreeGitStagedIcon" }, ord = 1 }
self.icons_by_status.unstaged = { str = glyphs.unstaged, hl = { "NvimTreeGitDirtyIcon" }, ord = 2 } self.icons_by_status.unstaged = { str = glyphs.unstaged, hl = { "NvimTreeGitDirtyIcon" }, ord = 2 }
self.icons_by_status.renamed = { str = glyphs.renamed, hl = { "NvimTreeGitRenamedIcon" }, ord = 3 } self.icons_by_status.renamed = { str = glyphs.renamed, hl = { "NvimTreeGitRenamedIcon" }, ord = 3 }
self.icons_by_status.deleted = { str = glyphs.deleted, hl = { "NvimTreeGitDeletedIcon" }, ord = 4 } self.icons_by_status.deleted = { str = glyphs.deleted, hl = { "NvimTreeGitDeletedIcon" }, ord = 4 }
self.icons_by_status.unmerged = { str = glyphs.unmerged, hl = { "NvimTreeGitMergeIcon" }, ord = 5 } self.icons_by_status.unmerged = { str = glyphs.unmerged, hl = { "NvimTreeGitMergeIcon" }, ord = 5 }
self.icons_by_status.untracked = { str = glyphs.untracked, hl = { "NvimTreeGitNewIcon" }, ord = 6 } self.icons_by_status.untracked = { str = glyphs.untracked, hl = { "NvimTreeGitNewIcon" }, ord = 6 }
self.icons_by_status.ignored = { str = glyphs.ignored, hl = { "NvimTreeGitIgnoredIcon" }, ord = 7 } self.icons_by_status.ignored = { str = glyphs.ignored, hl = { "NvimTreeGitIgnoredIcon" }, ord = 7 }
end end
---@param icons GitIconsByXY ---@param icons GitIconsByXY
@ -96,7 +96,7 @@ function DecoratorGit:build_icons_by_xy(icons)
["DD"] = { icons.deleted }, ["DD"] = { icons.deleted },
["DU"] = { icons.deleted, icons.unmerged }, ["DU"] = { icons.deleted, icons.unmerged },
["!!"] = { icons.ignored }, ["!!"] = { icons.ignored },
dirty = { icons.unstaged }, dirty = { icons.unstaged },
} }
end end
@ -115,7 +115,7 @@ function DecoratorGit:build_file_folder_hl_by_xy()
[" T"] = "NvimTreeGitFileDirtyHL", [" T"] = "NvimTreeGitFileDirtyHL",
["MM"] = "NvimTreeGitFileDirtyHL", ["MM"] = "NvimTreeGitFileDirtyHL",
["AM"] = "NvimTreeGitFileDirtyHL", ["AM"] = "NvimTreeGitFileDirtyHL",
dirty = "NvimTreeGitFileDirtyHL", dirty = "NvimTreeGitFileDirtyHL",
["A "] = "NvimTreeGitFileStagedHL", ["A "] = "NvimTreeGitFileStagedHL",
["??"] = "NvimTreeGitFileNewHL", ["??"] = "NvimTreeGitFileNewHL",
["AU"] = "NvimTreeGitFileMergeHL", ["AU"] = "NvimTreeGitFileMergeHL",

View File

@ -59,9 +59,9 @@ function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
for i, extname in pairs(extmarks) do for i, extname in pairs(extmarks) do
for _, mark in ipairs(extname) do for _, mark in ipairs(extname) do
vim.api.nvim_buf_set_extmark(bufnr, namespace_extmarks_id, i, -1, { vim.api.nvim_buf_set_extmark(bufnr, namespace_extmarks_id, i, -1, {
virt_text = { { mark.str, mark.hl } }, virt_text = { { mark.str, mark.hl } },
virt_text_pos = "right_align", virt_text_pos = "right_align",
hl_mode = "combine", hl_mode = "combine",
}) })
end end
end end
@ -69,8 +69,8 @@ function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
vim.api.nvim_buf_clear_namespace(bufnr, namespace_virtual_lines_id, 0, -1) vim.api.nvim_buf_clear_namespace(bufnr, namespace_virtual_lines_id, 0, -1)
for line_nr, vlines in pairs(virtual_lines) do for line_nr, vlines in pairs(virtual_lines) do
vim.api.nvim_buf_set_extmark(bufnr, namespace_virtual_lines_id, line_nr, 0, { vim.api.nvim_buf_set_extmark(bufnr, namespace_virtual_lines_id, line_nr, 0, {
virt_lines = vlines, virt_lines = vlines,
virt_lines_above = false, virt_lines_above = false,
virt_lines_leftcol = true, virt_lines_leftcol = true,
}) })
end end

View File

@ -15,31 +15,31 @@ local DEFAULT_MAX_WIDTH = -1
local DEFAULT_PADDING = 1 local DEFAULT_PADDING = 1
M.View = { M.View = {
adaptive_size = false, adaptive_size = false,
centralize_selection = false, centralize_selection = false,
tabpages = {}, tabpages = {},
cursors = {}, cursors = {},
hide_root_folder = false, hide_root_folder = false,
live_filter = { live_filter = {
prev_focused_node = nil, prev_focused_node = nil,
}, },
winopts = { winopts = {
relativenumber = false, relativenumber = false,
number = false, number = false,
list = false, list = false,
foldenable = false, foldenable = false,
winfixwidth = true, winfixwidth = true,
winfixheight = true, winfixheight = true,
spell = false, spell = false,
signcolumn = "yes", signcolumn = "yes",
foldmethod = "manual", foldmethod = "manual",
foldcolumn = "0", foldcolumn = "0",
cursorcolumn = false, cursorcolumn = false,
cursorline = true, cursorline = true,
cursorlineopt = "both", cursorlineopt = "both",
colorcolumn = "0", colorcolumn = "0",
wrap = false, wrap = false,
winhl = table.concat({ winhl = table.concat({
"EndOfBuffer:NvimTreeEndOfBuffer", "EndOfBuffer:NvimTreeEndOfBuffer",
"CursorLine:NvimTreeCursorLine", "CursorLine:NvimTreeCursorLine",
"CursorLineNr:NvimTreeCursorLineNr", "CursorLineNr:NvimTreeCursorLineNr",