From 40c911f82120845663599e7068eea0f31bd5dad9 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 25 Oct 2024 13:16:50 +1100 Subject: [PATCH 01/11] chore: luacheckrc uses table --- .luacheckrc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 1719373fa11..267d0ce54ce 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -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 From 59b5ce5582e68c02d6c217b8e67fe7d366989e8d Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 25 Oct 2024 13:17:00 +1100 Subject: [PATCH 02/11] chore: format nvt-min.lua --- .github/ISSUE_TEMPLATE/nvt-min.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/nvt-min.lua b/.github/ISSUE_TEMPLATE/nvt-min.lua index 228475dd2a2..858768cf34a 100644 --- a/.github/ISSUE_TEMPLATE/nvt-min.lua +++ b/.github/ISSUE_TEMPLATE/nvt-min.lua @@ -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. From 3fcba33d0376df510e67f0f6a8aa5a5a1ab2d4fe Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 25 Oct 2024 13:31:10 +1100 Subject: [PATCH 03/11] chore: complete lua doc --- lua/nvim-tree/actions/moves/parent.lua | 3 ++- lua/nvim-tree/actions/node/open-file.lua | 15 ++++++++++----- lua/nvim-tree/explorer/filters.lua | 2 ++ lua/nvim-tree/explorer/init.lua | 9 +++++---- lua/nvim-tree/renderer/init.lua | 2 ++ lua/nvim-tree/view.lua | 2 ++ 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lua/nvim-tree/actions/moves/parent.lua b/lua/nvim-tree/actions/moves/parent.lua index 9502af46f1c..32ca8398116 100644 --- a/lua/nvim-tree/actions/moves/parent.lua +++ b/lua/nvim-tree/actions/moves/parent.lua @@ -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) diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 25c74451204..0add341c0f7 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -375,19 +375,23 @@ function M.fn(mode, filename) end if mode == "tabnew" then - return open_file_in_tab(filename) + open_file_in_tab(filename) + return end if mode == "drop" then - return drop(filename) + drop(filename) + return end if mode == "tab_drop" then - return tab_drop(filename) + tab_drop(filename) + return end if mode == "edit_in_place" then - return edit_in_current_buf(filename) + edit_in_current_buf(filename) + return end local buf_loaded = is_already_loaded(filename) @@ -409,7 +413,8 @@ function M.fn(mode, filename) end if mode == "preview" or mode == "preview_no_picker" then - return on_preview(buf_loaded) + on_preview(buf_loaded) + return end if M.quit_on_open then diff --git a/lua/nvim-tree/explorer/filters.lua b/lua/nvim-tree/explorer/filters.lua index 5dd595d5999..6cf21d4aad9 100644 --- a/lua/nvim-tree/explorer/filters.lua +++ b/lua/nvim-tree/explorer/filters.lua @@ -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 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 diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua index b0cbc99665a..e303ee7b718 100644 --- a/lua/nvim-tree/explorer/init.lua +++ b/lua/nvim-tree/explorer/init.lua @@ -80,11 +80,12 @@ 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) if not handle then - return + return nil end local profile = log.profile_start("reload %s", node.absolute_path) @@ -173,10 +174,10 @@ function Explorer:reload(node, git_status) local single_child = node:single_child_directory() if config.renderer.group_empty and node.parent and single_child then node.group_next = single_child - local ns = self:reload(single_child, git_status) - node.nodes = ns or {} + local nodes = self:reload(single_child, git_status) + node.nodes = nodes or {} log.profile_end(profile) - return ns + return nodes end self.sorters:sort(node.nodes) diff --git a/lua/nvim-tree/renderer/init.lua b/lua/nvim-tree/renderer/init.lua index 755cbe55ae0..e222e709b30 100644 --- a/lua/nvim-tree/renderer/init.lua +++ b/lua/nvim-tree/renderer/init.lua @@ -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 }) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index ce9b257c468..a39df75a684 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -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 From d1d5096793ec7ed51e6b8e562e761f9444a2bfc4 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 25 Oct 2024 13:34:47 +1100 Subject: [PATCH 04/11] chore: complete lua doc --- lua/nvim-tree/help.lua | 1 + lua/nvim-tree/log.lua | 2 +- lua/nvim-tree/renderer/components/padding.lua | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/nvim-tree/help.lua b/lua/nvim-tree/help.lua index ab4dfd85781..e5d6e8a6c0e 100644 --- a/lua/nvim-tree/help.lua +++ b/lua/nvim-tree/help.lua @@ -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 diff --git a/lua/nvim-tree/log.lua b/lua/nvim-tree/log.lua index ad8f34cf175..7f02383ae68 100644 --- a/lua/nvim-tree/log.lua +++ b/lua/nvim-tree/log.lua @@ -92,7 +92,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 node = node or require("nvim-tree.lib").get_node_at_cursor() diff --git a/lua/nvim-tree/renderer/components/padding.lua b/lua/nvim-tree/renderer/components/padding.lua index 8ca25e8a6cf..fa34c23e13c 100644 --- a/lua/nvim-tree/renderer/components/padding.lua +++ b/lua/nvim-tree/renderer/components/padding.lua @@ -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 = "" From c7c636b9fd7ebf6fe28a76cf67a88602fbeb459a Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 25 Oct 2024 13:41:58 +1100 Subject: [PATCH 05/11] chore: complete lua doc --- .../actions/tree/modifiers/expand-all.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lua/nvim-tree/actions/tree/modifiers/expand-all.lua b/lua/nvim-tree/actions/tree/modifiers/expand-all.lua index ffede0e6d6f..6032c686545 100644 --- a/lua/nvim-tree/actions/tree/modifiers/expand-all.lua +++ b/lua/nvim-tree/actions/tree/modifiers/expand-all.lua @@ -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 - expand(node) + 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) From f31c01b72cc85e97e1bb0fc773f6a2288f9c4f8e Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 25 Oct 2024 13:43:31 +1100 Subject: [PATCH 06/11] chore: complete lua doc --- lua/nvim-tree/explorer/live-filter.lua | 1 + lua/nvim-tree/explorer/sorters.lua | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lua/nvim-tree/explorer/live-filter.lua b/lua/nvim-tree/explorer/live-filter.lua index 30152d63ae4..9c900483547 100644 --- a/lua/nvim-tree/explorer/live-filter.lua +++ b/lua/nvim-tree/explorer/live-filter.lua @@ -13,6 +13,7 @@ local LiveFilter = {} ---@param opts table ---@param explorer Explorer +---@return LiveFilter function LiveFilter:new(opts, explorer) local o = { explorer = explorer, diff --git a/lua/nvim-tree/explorer/sorters.lua b/lua/nvim-tree/explorer/sorters.lua index bcf55900af5..25981e02ac3 100644 --- a/lua/nvim-tree/explorer/sorters.lua +++ b/lua/nvim-tree/explorer/sorters.lua @@ -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 From c34b04216b2d721b51e33ac5c987f1c8a22798a1 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 25 Oct 2024 14:12:31 +1100 Subject: [PATCH 07/11] chore: complete lua doc --- lua/nvim-tree/api.lua | 18 ++++++++++-------- lua/nvim-tree/explorer/sorters.lua | 2 +- lua/nvim-tree/keymap.lua | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 7daab9a1ae2..192ec3c24eb 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -42,13 +42,12 @@ local Api = { } --- Print error when setup not called. ---- f function to invoke ----@param f function ----@return fun(...) : any -local function wrap(f) +---@param fn fun(...) +---@return fun(...) +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 @@ -56,7 +55,8 @@ local function wrap(f) end ---Inject the node as the first argument if present otherwise do nothing. ----@param fn function function to invoke +---@param fn fun(node: Node, ...) +---@return fun(node: Node, ...) local function wrap_node(fn) return function(node, ...) node = node or lib.get_node_at_cursor() @@ -67,7 +67,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, ...) +---@return fun(node: Node, ...) local function wrap_node_or_nil(fn) return function(node, ...) node = node or lib.get_node_at_cursor() @@ -211,6 +212,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 @@ -286,7 +288,7 @@ Api.config.mappings.default_on_attach = keymap.default_on_attach Api.diagnostics.hi_test = wrap(appearance_diagnostics.hi_test) Api.commands.get = wrap(function() - return require("nvim-tree.commands").get() + require("nvim-tree.commands").get() end) return Api diff --git a/lua/nvim-tree/explorer/sorters.lua b/lua/nvim-tree/explorer/sorters.lua index 25981e02ac3..f9e00166b1b 100644 --- a/lua/nvim-tree/explorer/sorters.lua +++ b/lua/nvim-tree/explorer/sorters.lua @@ -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) diff --git a/lua/nvim-tree/keymap.lua b/lua/nvim-tree/keymap.lua index f37b15c082f..94029de5818 100644 --- a/lua/nvim-tree/keymap.lua +++ b/lua/nvim-tree/keymap.lua @@ -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 From fe03da8c48216116afaec93e8cc983b0b79a324f Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 25 Oct 2024 14:12:44 +1100 Subject: [PATCH 08/11] chore: enable incomplete-signature-doc --- .luarc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.luarc.json b/.luarc.json index 1ff3e644a58..d8b3e691d55 100644 --- a/.luarc.json +++ b/.luarc.json @@ -33,7 +33,7 @@ "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", From ea49c0ca7d23f6bc83a9e271a8dfa6c3b3756ea9 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 25 Oct 2024 14:20:06 +1100 Subject: [PATCH 09/11] chore: enable incomplete-signature-doc --- lua/nvim-tree/api.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 192ec3c24eb..c0fe06bdb77 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -42,8 +42,8 @@ local Api = { } --- Print error when setup not called. ----@param fn fun(...) ----@return fun(...) +---@param fn fun(...): any +---@return fun(...): any local function wrap(fn) return function(...) if vim.g.NvimTreeSetup == 1 then @@ -55,8 +55,8 @@ local function wrap(fn) end ---Inject the node as the first argument if present otherwise do nothing. ----@param fn fun(node: Node, ...) ----@return fun(node: Node, ...) +---@param fn fun(node: Node, ...): any +---@return fun(node: Node, ...): any local function wrap_node(fn) return function(node, ...) node = node or lib.get_node_at_cursor() @@ -67,8 +67,8 @@ local function wrap_node(fn) end ---Inject the node or nil as the first argument if absent. ----@param fn fun(node: Node, ...) ----@return fun(node: Node, ...) +---@param fn fun(node: Node, ...): any +---@return fun(node: Node, ...): any local function wrap_node_or_nil(fn) return function(node, ...) node = node or lib.get_node_at_cursor() @@ -79,7 +79,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() @@ -93,7 +93,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() @@ -288,7 +288,7 @@ Api.config.mappings.default_on_attach = keymap.default_on_attach Api.diagnostics.hi_test = wrap(appearance_diagnostics.hi_test) Api.commands.get = wrap(function() - require("nvim-tree.commands").get() + return require("nvim-tree.commands").get() end) return Api From 46c6b428bf37a849ee42f60f521b5db366303b0f Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 25 Oct 2024 14:22:04 +1100 Subject: [PATCH 10/11] chore: complete lua doc --- lua/nvim-tree/explorer/init.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua index e303ee7b718..43563f8446d 100644 --- a/lua/nvim-tree/explorer/init.lua +++ b/lua/nvim-tree/explorer/init.lua @@ -85,7 +85,7 @@ function Explorer:reload(node, git_status) local cwd = node.link_to or node.absolute_path local handle = vim.loop.fs_scandir(cwd) if not handle then - return nil + return end local profile = log.profile_start("reload %s", node.absolute_path) @@ -174,10 +174,10 @@ function Explorer:reload(node, git_status) local single_child = node:single_child_directory() if config.renderer.group_empty and node.parent and single_child then node.group_next = single_child - local nodes = self:reload(single_child, git_status) - node.nodes = nodes or {} + local ns = self:reload(single_child, git_status) + node.nodes = ns or {} log.profile_end(profile) - return nodes + return ns end self.sorters:sort(node.nodes) From d924108605a9f0b7ef861142df3843446e86e989 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Fri, 25 Oct 2024 14:23:41 +1100 Subject: [PATCH 11/11] chore: complete lua doc --- lua/nvim-tree/actions/node/open-file.lua | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 0add341c0f7..92086df4aeb 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -369,29 +369,26 @@ end ---@param mode string ---@param filename string +---@return nil function M.fn(mode, filename) if type(mode) ~= "string" then mode = "" end if mode == "tabnew" then - open_file_in_tab(filename) - return + return open_file_in_tab(filename) end if mode == "drop" then - drop(filename) - return + return drop(filename) end if mode == "tab_drop" then - tab_drop(filename) - return + return tab_drop(filename) end if mode == "edit_in_place" then - edit_in_current_buf(filename) - return + return edit_in_current_buf(filename) end local buf_loaded = is_already_loaded(filename) @@ -413,8 +410,7 @@ function M.fn(mode, filename) end if mode == "preview" or mode == "preview_no_picker" then - on_preview(buf_loaded) - return + return on_preview(buf_loaded) end if M.quit_on_open then