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_netrwPlugin = 1
vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvt-min/site]]
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvt-min/site]])
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
require("packer").startup {
require("packer").startup({
{
"wbthomason/packer.nvim",
"nvim-tree/nvim-tree.lua",
@@ -18,21 +18,21 @@ local function load_plugins()
compile_path = install_path .. "/plugin/packer_compiled.lua",
display = { non_interactive = true },
},
}
})
end
if vim.fn.isdirectory(install_path) == 0 then
print "Installing nvim-tree and dependencies."
vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }
print("Installing nvim-tree and dependencies.")
vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
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.cursorline = true
-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
require("nvim-tree").setup {}
require("nvim-tree").setup({})
end
-- 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.
self = false
M.self = false
ignore = {
M.ignore = {
"631", -- max_line_length
}
-- Global objects defined by the C code
globals = {
M.globals = {
"vim",
"TreeExplorer"
}
return M

View File

@@ -33,13 +33,13 @@
"empty-block": "Any",
"global-element": "Any",
"global-in-nil-env": "Any",
"incomplete-signature-doc": "None",
"incomplete-signature-doc": "Any",
"inject-field": "Any",
"invisible": "Any",
"lowercase-global": "Any",
"missing-fields": "Any",
"missing-global-doc": "Any",
"missing-local-export-doc": "None",
"missing-local-export-doc": "Any",
"missing-parameter": "Any",
"missing-return": "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
if not parent or not parent.parent then
return view.set_cursor({ 1, 0 })
view.set_cursor({ 1, 0 })
return
end
local _, line = utils.find_node(parent.explorer.nodes, function(n)

View File

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

View File

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

View File

@@ -40,14 +40,13 @@ local Api = {
diagnostics = {},
}
--- Print error when setup not called.
--- f function to invoke
---@param f function
---@return fun(...) : any
local function wrap(f)
---Print error when setup not called.
---@param fn fun(...): any
---@return fun(...): any
local function wrap(fn)
return function(...)
if vim.g.NvimTreeSetup == 1 then
return f(...)
return fn(...)
else
notify.error("nvim-tree setup not called")
end
@@ -57,7 +56,7 @@ end
---Invoke a method on the singleton explorer.
---Print error when setup not called.
---@param explorer_method string explorer method name
---@return fun(...) : any
---@return fun(...): any
local function wrap_explorer(explorer_method)
return wrap(function(...)
local explorer = core.get_explorer()
@@ -68,7 +67,8 @@ local function wrap_explorer(explorer_method)
end
---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)
return function(node, ...)
node = node or wrap_explorer("get_node_at_cursor")()
@@ -79,7 +79,8 @@ local function wrap_node(fn)
end
---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)
return function(node, ...)
node = node or wrap_explorer("get_node_at_cursor")()
@@ -91,7 +92,7 @@ end
---Print error when setup not called.
---@param explorer_member string explorer member name
---@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)
return wrap(function(...)
local explorer = core.get_explorer()
@@ -210,6 +211,7 @@ local function edit(mode, node)
end
---@param mode string
---@param toggle_group boolean?
---@return fun(node: Node)
local function open_or_expand_or_dir_up(mode, toggle_group)
---@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) == "."
end
---Bookmark is present
---@param path string
---@param path_type string|nil filetype of path
---@param bookmarks table<string, string|nil> path, filetype table of bookmarked files
---@return boolean
local function bookmark(self, path, path_type, bookmarks)
if not self.config.filter_no_bookmark then
return false

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
local M = {}
--- 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
local function generate_keymap(fn)
-- create an unlisted scratch buffer

View File

@@ -91,7 +91,7 @@ end
---@param typ string as per log.types config
---@param node Node node to be inspected
---@param fmt string for string.format
---@vararg any arguments for string.format
---@param ... any arguments for string.format
function M.node(typ, node, fmt, ...)
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)), ...)

View File

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

View File

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

View File

@@ -41,6 +41,8 @@ end
---@param lines string[]
---@param hl_args AddHighlightArgs[]
---@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)
if vim.fn.has("nvim-0.10") == 1 then
vim.api.nvim_set_option_value("modifiable", true, { buf = bufnr })

View File

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