Merge remote-tracking branch 'origin/master' into 2941-move-lib-to-explorer

This commit is contained in:
Alexander Courtis
2024-10-26 09:11:13 +11:00
18 changed files with 74 additions and 37 deletions

View File

@@ -1,12 +1,12 @@
vim.g.loaded_netrw = 1 vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1 vim.g.loaded_netrwPlugin = 1
vim.cmd [[set runtimepath=$VIMRUNTIME]] vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd [[set packpath=/tmp/nvt-min/site]] vim.cmd([[set packpath=/tmp/nvt-min/site]])
local package_root = "/tmp/nvt-min/site/pack" local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim" local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins() local function load_plugins()
require("packer").startup { require("packer").startup({
{ {
"wbthomason/packer.nvim", "wbthomason/packer.nvim",
"nvim-tree/nvim-tree.lua", "nvim-tree/nvim-tree.lua",
@@ -18,21 +18,21 @@ local function load_plugins()
compile_path = install_path .. "/plugin/packer_compiled.lua", compile_path = install_path .. "/plugin/packer_compiled.lua",
display = { non_interactive = true }, display = { non_interactive = true },
}, },
} })
end end
if vim.fn.isdirectory(install_path) == 0 then if vim.fn.isdirectory(install_path) == 0 then
print "Installing nvim-tree and dependencies." print("Installing nvim-tree and dependencies.")
vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path } vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end end
load_plugins() load_plugins()
require("packer").sync() require("packer").sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]] vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]])
vim.opt.termguicolors = true vim.opt.termguicolors = true
vim.opt.cursorline = true vim.opt.cursorline = true
-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE -- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function() _G.setup = function()
require("nvim-tree").setup {} require("nvim-tree").setup({})
end end
-- UNCOMMENT this block for diagnostics issues, substituting pattern and cmd as appropriate. -- UNCOMMENT this block for diagnostics issues, substituting pattern and cmd as appropriate.

View File

@@ -1,14 +1,15 @@
-- vim: ft=lua tw=80 local M = {}
-- Don't report unused self arguments of methods. -- Don't report unused self arguments of methods.
self = false M.self = false
ignore = { M.ignore = {
"631", -- max_line_length "631", -- max_line_length
} }
-- Global objects defined by the C code -- Global objects defined by the C code
globals = { M.globals = {
"vim", "vim",
"TreeExplorer"
} }
return M

View File

@@ -33,13 +33,13 @@
"empty-block": "Any", "empty-block": "Any",
"global-element": "Any", "global-element": "Any",
"global-in-nil-env": "Any", "global-in-nil-env": "Any",
"incomplete-signature-doc": "None", "incomplete-signature-doc": "Any",
"inject-field": "Any", "inject-field": "Any",
"invisible": "Any", "invisible": "Any",
"lowercase-global": "Any", "lowercase-global": "Any",
"missing-fields": "Any", "missing-fields": "Any",
"missing-global-doc": "Any", "missing-global-doc": "Any",
"missing-local-export-doc": "None", "missing-local-export-doc": "Any",
"missing-parameter": "Any", "missing-parameter": "Any",
"missing-return": "Any", "missing-return": "Any",
"missing-return-value": "Any", "missing-return-value": "Any",

View File

@@ -25,7 +25,8 @@ function M.fn(should_close)
local parent = (node:get_parent_of_group() or node).parent local parent = (node:get_parent_of_group() or node).parent
if not parent or not parent.parent then if not parent or not parent.parent then
return view.set_cursor({ 1, 0 }) view.set_cursor({ 1, 0 })
return
end end
local _, line = utils.find_node(parent.explorer.nodes, function(n) local _, line = utils.find_node(parent.explorer.nodes, function(n)

View File

@@ -369,6 +369,7 @@ end
---@param mode string ---@param mode string
---@param filename string ---@param filename string
---@return nil
function M.fn(mode, filename) function M.fn(mode, filename)
if type(mode) ~= "string" then if type(mode) ~= "string" then
mode = "" mode = ""

View File

@@ -30,15 +30,18 @@ end
---@param node Node ---@param node Node
---@return boolean ---@return boolean
local function should_expand(expansion_count, node) local function should_expand(expansion_count, node)
local dir = node:as(DirectoryNode)
if not dir then
return false
end
local should_halt = expansion_count >= M.MAX_FOLDER_DISCOVERY local should_halt = expansion_count >= M.MAX_FOLDER_DISCOVERY
local should_exclude = M.EXCLUDE[node.name] local should_exclude = M.EXCLUDE[dir.name]
return not should_halt and node.nodes and not node.open and not should_exclude return not should_halt and not dir.open and not should_exclude
end end
local function gen_iterator() local function gen_iterator()
local expansion_count = 0 local expansion_count = 0
---@param parent DirectoryNode
return function(parent) return function(parent)
if parent.parent and parent.nodes and not parent.open then if parent.parent and parent.nodes and not parent.open then
expansion_count = expansion_count + 1 expansion_count = expansion_count + 1
@@ -47,14 +50,15 @@ local function gen_iterator()
Iterator.builder(parent.nodes) Iterator.builder(parent.nodes)
:hidden() :hidden()
---@param node DirectoryNode
:applier(function(node) :applier(function(node)
if should_expand(expansion_count, node) then if should_expand(expansion_count, node) then
expansion_count = expansion_count + 1 expansion_count = expansion_count + 1
node = node:as(DirectoryNode)
if node then
expand(node) expand(node)
end end
end
end) end)
---@param node DirectoryNode
:recursor(function(node) :recursor(function(node)
return expansion_count < M.MAX_FOLDER_DISCOVERY and (node.group_next and { node.group_next } or (node.open and node.nodes)) return expansion_count < M.MAX_FOLDER_DISCOVERY and (node.group_next and { node.group_next } or (node.open and node.nodes))
end) end)

View File

@@ -40,14 +40,13 @@ local Api = {
diagnostics = {}, diagnostics = {},
} }
--- Print error when setup not called. ---Print error when setup not called.
--- f function to invoke ---@param fn fun(...): any
---@param f function ---@return fun(...): any
---@return fun(...) : any local function wrap(fn)
local function wrap(f)
return function(...) return function(...)
if vim.g.NvimTreeSetup == 1 then if vim.g.NvimTreeSetup == 1 then
return f(...) return fn(...)
else else
notify.error("nvim-tree setup not called") notify.error("nvim-tree setup not called")
end end
@@ -57,7 +56,7 @@ end
---Invoke a method on the singleton explorer. ---Invoke a method on the singleton explorer.
---Print error when setup not called. ---Print error when setup not called.
---@param explorer_method string explorer method name ---@param explorer_method string explorer method name
---@return fun(...) : any ---@return fun(...): any
local function wrap_explorer(explorer_method) local function wrap_explorer(explorer_method)
return wrap(function(...) return wrap(function(...)
local explorer = core.get_explorer() local explorer = core.get_explorer()
@@ -68,7 +67,8 @@ local function wrap_explorer(explorer_method)
end end
---Inject the node as the first argument if present otherwise do nothing. ---Inject the node as the first argument if present otherwise do nothing.
---@param fn function function to invoke ---@param fn fun(node: Node, ...): any
---@return fun(node: Node, ...): any
local function wrap_node(fn) local function wrap_node(fn)
return function(node, ...) return function(node, ...)
node = node or wrap_explorer("get_node_at_cursor")() node = node or wrap_explorer("get_node_at_cursor")()
@@ -79,7 +79,8 @@ local function wrap_node(fn)
end end
---Inject the node or nil as the first argument if absent. ---Inject the node or nil as the first argument if absent.
---@param fn function function to invoke ---@param fn fun(node: Node, ...): any
---@return fun(node: Node, ...): any
local function wrap_node_or_nil(fn) local function wrap_node_or_nil(fn)
return function(node, ...) return function(node, ...)
node = node or wrap_explorer("get_node_at_cursor")() node = node or wrap_explorer("get_node_at_cursor")()
@@ -91,7 +92,7 @@ end
---Print error when setup not called. ---Print error when setup not called.
---@param explorer_member string explorer member name ---@param explorer_member string explorer member name
---@param member_method string method name to invoke on member ---@param member_method string method name to invoke on member
---@return fun(...) : any ---@return fun(...): any
local function wrap_explorer_member(explorer_member, member_method) local function wrap_explorer_member(explorer_member, member_method)
return wrap(function(...) return wrap(function(...)
local explorer = core.get_explorer() local explorer = core.get_explorer()
@@ -210,6 +211,7 @@ local function edit(mode, node)
end end
---@param mode string ---@param mode string
---@param toggle_group boolean?
---@return fun(node: Node) ---@return fun(node: Node)
local function open_or_expand_or_dir_up(mode, toggle_group) local function open_or_expand_or_dir_up(mode, toggle_group)
---@param node Node ---@param node Node

View File

@@ -107,9 +107,11 @@ local function dotfile(self, path)
return self.config.filter_dotfiles and utils.path_basename(path):sub(1, 1) == "." return self.config.filter_dotfiles and utils.path_basename(path):sub(1, 1) == "."
end end
---Bookmark is present
---@param path string ---@param path string
---@param path_type string|nil filetype of path ---@param path_type string|nil filetype of path
---@param bookmarks table<string, string|nil> path, filetype table of bookmarked files ---@param bookmarks table<string, string|nil> path, filetype table of bookmarked files
---@return boolean
local function bookmark(self, path, path_type, bookmarks) local function bookmark(self, path, path_type, bookmarks)
if not self.config.filter_no_bookmark then if not self.config.filter_no_bookmark then
return false return false

View File

@@ -188,6 +188,7 @@ end
---@param node DirectoryNode ---@param node DirectoryNode
---@param git_status table|nil ---@param git_status table|nil
---@return Node[]?
function Explorer:reload(node, git_status) function Explorer:reload(node, git_status)
local cwd = node.link_to or node.absolute_path local cwd = node.link_to or node.absolute_path
local handle = vim.loop.fs_scandir(cwd) local handle = vim.loop.fs_scandir(cwd)

View File

@@ -13,6 +13,7 @@ local LiveFilter = {}
---@param opts table ---@param opts table
---@param explorer Explorer ---@param explorer Explorer
---@return LiveFilter
function LiveFilter:new(opts, explorer) function LiveFilter:new(opts, explorer)
local o = { local o = {
explorer = explorer, explorer = explorer,

View File

@@ -17,7 +17,7 @@ end
--- Predefined comparator, defaulting to name --- Predefined comparator, defaulting to name
---@param sorter string as per options ---@param sorter string as per options
---@return function ---@return fun(a: Node, b: Node): boolean
function Sorter:get_comparator(sorter) function Sorter:get_comparator(sorter)
return function(a, b) return function(a, b)
return (C[sorter] or C.name)(a, b, self.config) return (C[sorter] or C.name)(a, b, self.config)
@@ -41,6 +41,7 @@ end
---Evaluate `sort.folders_first` and `sort.files_first` ---Evaluate `sort.folders_first` and `sort.files_first`
---@param a Node ---@param a Node
---@param b Node ---@param b Node
---@param cfg table
---@return boolean|nil ---@return boolean|nil
local function folders_or_files_first(a, b, cfg) local function folders_or_files_first(a, b, cfg)
if not (cfg.folders_first or cfg.files_first) then if not (cfg.folders_first or cfg.files_first) then
@@ -164,6 +165,7 @@ end
---@param a Node ---@param a Node
---@param b Node ---@param b Node
---@param ignorecase boolean|nil ---@param ignorecase boolean|nil
---@param cfg table
---@return boolean ---@return boolean
local function node_comparator_name_ignorecase_or_not(a, b, ignorecase, cfg) local function node_comparator_name_ignorecase_or_not(a, b, ignorecase, cfg)
if not (a and b) then if not (a and b) then

View File

@@ -53,6 +53,7 @@ end
--- sort vim command lhs roughly as per :help index --- sort vim command lhs roughly as per :help index
---@param a string ---@param a string
---@param b string ---@param b string
---@return boolean
local function sort_lhs(a, b) local function sort_lhs(a, b)
-- mouse first -- mouse first
if a:match(PAT_MOUSE) and not b:match(PAT_MOUSE) then if a:match(PAT_MOUSE) and not b:match(PAT_MOUSE) then

View File

@@ -1,7 +1,7 @@
local M = {} local M = {}
--- Apply mappings to a scratch buffer and return buffer local mappings --- Apply mappings to a scratch buffer and return buffer local mappings
---@param fn function(bufnr) on_attach or default_on_attach ---@param fn fun(bufnr: integer) on_attach or default_on_attach
---@return table as per vim.api.nvim_buf_get_keymap ---@return table as per vim.api.nvim_buf_get_keymap
local function generate_keymap(fn) local function generate_keymap(fn)
-- create an unlisted scratch buffer -- create an unlisted scratch buffer

View File

@@ -91,7 +91,7 @@ end
---@param typ string as per log.types config ---@param typ string as per log.types config
---@param node Node node to be inspected ---@param node Node node to be inspected
---@param fmt string for string.format ---@param fmt string for string.format
---@vararg any arguments for string.format ---@param ... any arguments for string.format
function M.node(typ, node, fmt, ...) function M.node(typ, node, fmt, ...)
if M.enabled(typ) then if M.enabled(typ) then
M.raw(typ, string.format("[%s] [%s] %s\n%s\n", os.date("%Y-%m-%d %H:%M:%S"), typ, (fmt or "???"), vim.inspect(node, inspect_opts)), ...) M.raw(typ, string.format("[%s] [%s] %s\n%s\n", os.date("%Y-%m-%d %H:%M:%S"), typ, (fmt or "???"), vim.inspect(node, inspect_opts)), ...)

View File

@@ -5,10 +5,16 @@ local function config_symlinks()
M.i.symlink_arrow = M.config.symlink_arrow M.i.symlink_arrow = M.config.symlink_arrow
end end
---@return string icon
---@return string? name
local function empty() local function empty()
return "" return "", nil
end end
---@param node Node
---@param has_children boolean
---@return string icon
---@return string? name
local function get_folder_icon_default(node, has_children) local function get_folder_icon_default(node, has_children)
local is_symlink = node.links_to ~= nil local is_symlink = node.links_to ~= nil
local n local n
@@ -32,6 +38,10 @@ local function get_folder_icon_default(node, has_children)
return n, nil return n, nil
end end
---@param node Node
---@param has_children boolean
---@return string icon
---@return string? name
local function get_folder_icon_webdev(node, has_children) local function get_folder_icon_webdev(node, has_children)
local icon, hl_group = M.devicons.get_icon(node.name, node.extension) local icon, hl_group = M.devicons.get_icon(node.name, node.extension)
if not M.config.web_devicons.folder.color then if not M.config.web_devicons.folder.color then
@@ -44,16 +54,22 @@ local function get_folder_icon_webdev(node, has_children)
end end
end end
---@return string icon
---@return string? name
local function get_file_icon_default() local function get_file_icon_default()
local hl_group = "NvimTreeFileIcon" local hl_group = "NvimTreeFileIcon"
local icon = M.config.glyphs.default local icon = M.config.glyphs.default
if #icon > 0 then if #icon > 0 then
return icon, hl_group return icon, hl_group
else else
return "" return "", nil
end end
end end
---@param fname string
---@param extension string
---@return string icon
---@return string? name
local function get_file_icon_webdev(fname, extension) local function get_file_icon_webdev(fname, extension)
local icon, hl_group = M.devicons.get_icon(fname, extension) local icon, hl_group = M.devicons.get_icon(fname, extension)
if not M.config.web_devicons.file.color then if not M.config.web_devicons.file.color then

View File

@@ -61,6 +61,7 @@ end
---@param nodes_number integer ---@param nodes_number integer
---@param node Node ---@param node Node
---@param markers table ---@param markers table
---@param early_stop integer?
---@return HighlightedString[] ---@return HighlightedString[]
function M.get_indent_markers(depth, idx, nodes_number, node, markers, early_stop) function M.get_indent_markers(depth, idx, nodes_number, node, markers, early_stop)
local str = "" local str = ""

View File

@@ -41,6 +41,8 @@ end
---@param lines string[] ---@param lines string[]
---@param hl_args AddHighlightArgs[] ---@param hl_args AddHighlightArgs[]
---@param signs string[] ---@param signs string[]
---@param extmarks table[] extra marks for right icon placement
---@param virtual_lines table[] virtual lines for hidden count display
function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines) function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
if vim.fn.has("nvim-0.10") == 1 then if vim.fn.has("nvim-0.10") == 1 then
vim.api.nvim_set_option_value("modifiable", true, { buf = bufnr }) vim.api.nvim_set_option_value("modifiable", true, { buf = bufnr })

View File

@@ -124,6 +124,7 @@ local function get_size(size)
end end
---@param size (fun():integer)|integer|nil ---@param size (fun():integer)|integer|nil
---@return integer
local function get_width(size) local function get_width(size)
if size then if size then
return get_size(size) return get_size(size)
@@ -411,6 +412,7 @@ function M.abandon_all_windows()
end end
---@param opts table|nil ---@param opts table|nil
---@return boolean
function M.is_visible(opts) function M.is_visible(opts)
if opts and opts.tabpage then if opts and opts.tabpage then
if M.View.tabpages[opts.tabpage] == nil then if M.View.tabpages[opts.tabpage] == nil then