From d4871d726b025945e4968e3c5d9fba4bf57de846 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 7 Oct 2023 14:54:58 +1100 Subject: [PATCH 1/2] chore: stylua column width 120 -> 140 --- .stylua.toml | 2 +- lua/nvim-tree.lua | 10 ++------ lua/nvim-tree/actions/fs/rename-file.lua | 4 +--- .../actions/tree-modifiers/expand-all.lua | 3 +-- lua/nvim-tree/explorer/explore.lua | 6 +---- lua/nvim-tree/explorer/filters.lua | 5 +--- lua/nvim-tree/help.lua | 10 ++------ lua/nvim-tree/legacy.lua | 10 +------- lua/nvim-tree/notify.lua | 3 --- lua/nvim-tree/renderer/builder.lua | 24 ++++--------------- lua/nvim-tree/renderer/components/padding.lua | 4 +--- lua/nvim-tree/utils.lua | 4 +--- 12 files changed, 16 insertions(+), 69 deletions(-) diff --git a/.stylua.toml b/.stylua.toml index ecb6dca5a03..ee66248283f 100644 --- a/.stylua.toml +++ b/.stylua.toml @@ -1,4 +1,4 @@ -column_width = 120 +column_width = 140 line_endings = "Unix" indent_type = "Spaces" indent_width = 2 diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 1ea23aa4b9c..d2552b84a53 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -218,10 +218,7 @@ local function setup_autocommands(opts) create_nvim_tree_autocmd("BufReadPost", { callback = function(data) -- update opened file buffers - if - (filters.config.filter_no_buffer or renderer.config.highlight_opened_files ~= "none") - and vim.bo[data.buf].buftype == "" - then + if (filters.config.filter_no_buffer or renderer.config.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == "" then utils.debounce("Buf:filter_buffer", opts.view.debounce_delay, function() reloaders.reload_explorer() end) @@ -232,10 +229,7 @@ local function setup_autocommands(opts) create_nvim_tree_autocmd("BufUnload", { callback = function(data) -- update opened file buffers - if - (filters.config.filter_no_buffer or renderer.config.highlight_opened_files ~= "none") - and vim.bo[data.buf].buftype == "" - then + if (filters.config.filter_no_buffer or renderer.config.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == "" then utils.debounce("Buf:filter_buffer", opts.view.debounce_delay, function() reloaders.reload_explorer(nil, data.buf) end) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index 4436fa14894..a21eb6c80b2 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -52,9 +52,7 @@ function M.fn(default_modifier) -- support for only specific modifiers have been implemented if not ALLOWED_MODIFIERS[modifier] then - return notify.warn( - "Modifier " .. vim.inspect(modifier) .. " is not in allowed list : " .. table.concat(ALLOWED_MODIFIERS, ",") - ) + return notify.warn("Modifier " .. vim.inspect(modifier) .. " is not in allowed list : " .. table.concat(ALLOWED_MODIFIERS, ",")) end node = lib.get_last_group_node(node) diff --git a/lua/nvim-tree/actions/tree-modifiers/expand-all.lua b/lua/nvim-tree/actions/tree-modifiers/expand-all.lua index fdc8e989f9e..30ecd86dc0b 100644 --- a/lua/nvim-tree/actions/tree-modifiers/expand-all.lua +++ b/lua/nvim-tree/actions/tree-modifiers/expand-all.lua @@ -47,8 +47,7 @@ local function gen_iterator() end end) :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) :iterate() diff --git a/lua/nvim-tree/explorer/explore.lua b/lua/nvim-tree/explorer/explore.lua index 792a9aa6a24..a8326599fa6 100644 --- a/lua/nvim-tree/explorer/explore.lua +++ b/lua/nvim-tree/explorer/explore.lua @@ -30,11 +30,7 @@ local function populate_children(handle, cwd, node, git_status) local profile = log.profile_start("explore populate_children %s", abs) t = get_type_from(t, abs) - if - not filters.should_filter(abs, filter_status) - and not nodes_by_path[abs] - and Watcher.is_fs_event_capable(abs) - then + if not filters.should_filter(abs, filter_status) and not nodes_by_path[abs] and Watcher.is_fs_event_capable(abs) then local child = nil if t == "directory" and vim.loop.fs_access(abs, "R") then child = builders.folder(node, abs, name) diff --git a/lua/nvim-tree/explorer/filters.lua b/lua/nvim-tree/explorer/filters.lua index ee8777529b2..4e332c798ff 100644 --- a/lua/nvim-tree/explorer/filters.lua +++ b/lua/nvim-tree/explorer/filters.lua @@ -121,10 +121,7 @@ function M.should_filter(path, status) return false end - return git(path, status.git_status) - or buf(path, status.bufinfo, status.unloaded_bufnr) - or dotfile(path) - or custom(path) + return git(path, status.git_status) or buf(path, status.bufinfo, status.unloaded_bufnr) or dotfile(path) or custom(path) end function M.setup(opts) diff --git a/lua/nvim-tree/help.lua b/lua/nvim-tree/help.lua index 18036996355..8ccbb1bfb49 100644 --- a/lua/nvim-tree/help.lua +++ b/lua/nvim-tree/help.lua @@ -109,8 +109,7 @@ local function compute() -- header, not padded local hl = { { "NvimTreeRootFolder", 0, 0, #head_lhs } } - local lines = - { ("%s%s%s"):format(head_lhs, string.rep(" ", max_desc + max_lhs - #head_lhs - #head_rhs + 2), head_rhs) } + local lines = { ("%s%s%s"):format(head_lhs, string.rep(" ", max_desc + max_lhs - #head_lhs - #head_rhs + 2), head_rhs) } local width = #lines[1] -- mappings, left padded 1 @@ -177,12 +176,7 @@ local function open() vim.wo[M.winnr].cursorline = M.config.cursorline -- quit binding - vim.keymap.set( - "n", - "q", - close, - { desc = "nvim-tree: exit help", buffer = M.bufnr, noremap = true, silent = true, nowait = true } - ) + vim.keymap.set("n", "q", close, { desc = "nvim-tree: exit help", buffer = M.bufnr, noremap = true, silent = true, nowait = true }) -- close window and delete buffer on leave vim.api.nvim_create_autocmd({ "BufLeave", "WinLeave" }, { diff --git a/lua/nvim-tree/legacy.lua b/lua/nvim-tree/legacy.lua index 80105bff0d3..6f8c60c7317 100644 --- a/lua/nvim-tree/legacy.lua +++ b/lua/nvim-tree/legacy.lua @@ -40,15 +40,7 @@ local function refactored(opts) utils.move_missing_val(opts, "git", "ignore", opts, "filters", "git_ignored", true) -- 2023/08/26 - utils.move_missing_val( - opts, - "renderer.icons", - "webdev_colors", - opts, - "renderer.icons.web_devicons.file", - "color", - true - ) + utils.move_missing_val(opts, "renderer.icons", "webdev_colors", opts, "renderer.icons.web_devicons.file", "color", true) end local function deprecated(opts) diff --git a/lua/nvim-tree/notify.lua b/lua/nvim-tree/notify.lua index e487e40d8a3..47b5f567146 100644 --- a/lua/nvim-tree/notify.lua +++ b/lua/nvim-tree/notify.lua @@ -7,15 +7,12 @@ local config = { local title_support function M.supports_title() - -- TODO increase stylua column_width - -- stylua: ignore start if title_support == nil then title_support = (package.loaded.notify and (vim.notify == require "notify" or vim.notify == require("notify").notify)) or (package.loaded.noice and (vim.notify == require("noice").notify or vim.notify == require("noice.source.notify").notify)) or (package.loaded.notifier and require("notifier.config").has_component "nvim") or false end - -- stylua: ignore end return title_support end diff --git a/lua/nvim-tree/renderer/builder.lua b/lua/nvim-tree/renderer/builder.lua index 727d16a3d31..4f933b10935 100644 --- a/lua/nvim-tree/renderer/builder.lua +++ b/lua/nvim-tree/renderer/builder.lua @@ -168,9 +168,7 @@ function Builder:_build_folder(node) local link_to = utils.path_relative(node.link_to, core.get_cwd()) foldername = foldername .. arrow .. link_to foldername_hl = "NvimTreeSymlinkFolderName" - elseif - vim.tbl_contains(self.special_files, node.absolute_path) or vim.tbl_contains(self.special_files, node.name) - then + elseif vim.tbl_contains(self.special_files, node.absolute_path) or vim.tbl_contains(self.special_files, node.name) then foldername_hl = "NvimTreeSpecialFolderName" elseif node.open then foldername_hl = "NvimTreeOpenedFolderName" @@ -278,11 +276,7 @@ function Builder:_get_highlight_override(node, unloaded_bufnr) end -- opened file - if - self.highlight_opened_files - and vim.fn.bufloaded(node.absolute_path) > 0 - and vim.fn.bufnr(node.absolute_path) ~= unloaded_bufnr - then + if self.highlight_opened_files and vim.fn.bufloaded(node.absolute_path) > 0 and vim.fn.bufnr(node.absolute_path) ~= unloaded_bufnr then if self.highlight_opened_files == "all" or self.highlight_opened_files == "name" then name_hl = "NvimTreeOpenedFile" end @@ -331,16 +325,7 @@ end ---@param modified_icon HighlightedString|nil ---@param bookmark_icon HighlightedString|nil ---@return HighlightedString[] -function Builder:_format_line( - indent_markers, - arrows, - icon, - name, - git_icons, - diagnostics_icon, - modified_icon, - bookmark_icon -) +function Builder:_format_line(indent_markers, arrows, icon, name, git_icons, diagnostics_icon, modified_icon, bookmark_icon) local added_len = 0 local function add_to_end(t1, t2) for _, v in ipairs(t2) do @@ -430,8 +415,7 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr) self:_append_highlight(node, diagnostics.get_highlight, icon.hl, name.hl) self:_append_highlight(node, copy_paste.get_highlight, icon.hl, name.hl) - local line = - self:_format_line(indent_markers, arrows, icon, name, git_icons, diagnostics_icon, modified_icon, bookmark_icon) + local line = self:_format_line(indent_markers, arrows, icon, name, git_icons, diagnostics_icon, modified_icon, bookmark_icon) self:_insert_line(self:_unwrap_highlighted_strings(line)) self.index = self.index + 1 diff --git a/lua/nvim-tree/renderer/components/padding.lua b/lua/nvim-tree/renderer/components/padding.lua index f3196f88908..d61a0b508de 100644 --- a/lua/nvim-tree/renderer/components/padding.lua +++ b/lua/nvim-tree/renderer/components/padding.lua @@ -30,9 +30,7 @@ local function get_padding_indent_markers(depth, idx, nodes_number, markers, wit for i = 1, depth do local glyph if idx == nodes_number and i == depth then - local bottom_width = M.config.indent_width - - 2 - + (with_arrows and not inline_arrows and has_folder_sibling and 2 or 0) + local bottom_width = M.config.indent_width - 2 + (with_arrows and not inline_arrows and has_folder_sibling and 2 or 0) glyph = M.config.indent_markers.icons.corner .. string.rep(M.config.indent_markers.icons.bottom, bottom_width) .. (M.config.indent_width > 1 and " " or "") diff --git a/lua/nvim-tree/utils.lua b/lua/nvim-tree/utils.lua index 9181d87296f..8e9261814ed 100644 --- a/lua/nvim-tree/utils.lua +++ b/lua/nvim-tree/utils.lua @@ -176,9 +176,7 @@ function M.rename_loaded_buffers(old_path, new_path) if vim.api.nvim_buf_is_loaded(buf) then local buf_name = vim.api.nvim_buf_get_name(buf) local exact_match = buf_name == old_path - local child_match = ( - buf_name:sub(1, #old_path) == old_path and buf_name:sub(#old_path + 1, #old_path + 1) == path_separator - ) + local child_match = (buf_name:sub(1, #old_path) == old_path and buf_name:sub(#old_path + 1, #old_path + 1) == path_separator) if exact_match or child_match then vim.api.nvim_buf_set_name(buf, new_path .. buf_name:sub(#old_path + 1)) -- to avoid the 'overwrite existing file' error message on write for From 266ca6e0d937ef50b0995ee03fd246e87290e63a Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 7 Oct 2023 14:56:56 +1100 Subject: [PATCH 2/2] chore: stylua column width 140 -> 160 --- .stylua.toml | 2 +- lua/nvim-tree/actions/node/open-file.lua | 8 +------- lua/nvim-tree/actions/node/system-open.lua | 18 +++++++----------- lua/nvim-tree/diagnostics.lua | 6 +----- lua/nvim-tree/git/runner.lua | 8 +------- lua/nvim-tree/modified.lua | 5 +---- lua/nvim-tree/renderer/components/git.lua | 6 +----- lua/nvim-tree/watcher.lua | 5 +---- 8 files changed, 14 insertions(+), 44 deletions(-) diff --git a/.stylua.toml b/.stylua.toml index ee66248283f..e9636bd047e 100644 --- a/.stylua.toml +++ b/.stylua.toml @@ -1,4 +1,4 @@ -column_width = 140 +column_width = 160 line_endings = "Unix" indent_type = "Spaces" indent_width = 2 diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 0add9560879..080c9240c79 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -62,13 +62,7 @@ local function pick_win_id() end if #M.window_picker.chars < #selectable then - notify.error( - string.format( - "More windows (%d) than actions.open_file.window_picker.chars (%d) - please add more.", - #selectable, - #M.window_picker.chars - ) - ) + notify.error(string.format("More windows (%d) than actions.open_file.window_picker.chars (%d) - please add more.", #selectable, #M.window_picker.chars)) return nil end diff --git a/lua/nvim-tree/actions/node/system-open.lua b/lua/nvim-tree/actions/node/system-open.lua index a5ff2bd17f1..44884f6e9ca 100644 --- a/lua/nvim-tree/actions/node/system-open.lua +++ b/lua/nvim-tree/actions/node/system-open.lua @@ -16,18 +16,14 @@ function M.fn(node) stderr = vim.loop.new_pipe(false), } table.insert(process.args, node.link_to or node.absolute_path) - process.handle, process.pid = vim.loop.spawn( - process.cmd, - { args = process.args, stdio = { nil, nil, process.stderr }, detached = true }, - function(code) - process.stderr:read_stop() - process.stderr:close() - process.handle:close() - if code ~= 0 then - notify.warn(string.format("system_open failed with return code %d: %s", code, process.errors)) - end + process.handle, process.pid = vim.loop.spawn(process.cmd, { args = process.args, stdio = { nil, nil, process.stderr }, detached = true }, function(code) + process.stderr:read_stop() + process.stderr:close() + process.handle:close() + if code ~= 0 then + notify.warn(string.format("system_open failed with return code %d: %s", code, process.errors)) end - ) + end) table.remove(process.args) if not process.handle then notify.warn(string.format("system_open failed to spawn command '%s': %s", process.cmd, process.pid)) diff --git a/lua/nvim-tree/diagnostics.lua b/lua/nvim-tree/diagnostics.lua index 22463319315..16633f9162a 100644 --- a/lua/nvim-tree/diagnostics.lua +++ b/lua/nvim-tree/diagnostics.lua @@ -95,11 +95,7 @@ function M.update() for line, node in pairs(nodes_by_line) do local nodepath = utils.canonical_path(node.absolute_path) log.line("diagnostics", " %d checking nodepath '%s'", line, nodepath) - if - M.show_on_dirs - and vim.startswith(bufpath:gsub("\\", "/"), nodepath:gsub("\\", "/") .. "/") - and (not node.open or M.show_on_open_dirs) - then + if M.show_on_dirs and vim.startswith(bufpath:gsub("\\", "/"), nodepath:gsub("\\", "/") .. "/") and (not node.open or M.show_on_open_dirs) then log.line("diagnostics", " matched fold node '%s'", node.absolute_path) node.diag_status = severity elseif nodepath == bufpath then diff --git a/lua/nvim-tree/git/runner.lua b/lua/nvim-tree/git/runner.lua index 008ebc46abe..aa93f5300f5 100644 --- a/lua/nvim-tree/git/runner.lua +++ b/lua/nvim-tree/git/runner.lua @@ -156,13 +156,7 @@ function Runner:_finalise(opts) log.line("git", "job timed out %s %s", opts.toplevel, opts.path) timeouts = timeouts + 1 if timeouts == MAX_TIMEOUTS then - notify.warn( - string.format( - "%d git jobs have timed out after %dms, disabling git integration. Try increasing git.timeout", - timeouts, - opts.timeout - ) - ) + notify.warn(string.format("%d git jobs have timed out after %dms, disabling git integration. Try increasing git.timeout", timeouts, opts.timeout)) require("nvim-tree.git").disable_git_integration() end elseif self.rc ~= 0 then diff --git a/lua/nvim-tree/modified.lua b/lua/nvim-tree/modified.lua index 51025e1b22f..d4df3bd6751 100644 --- a/lua/nvim-tree/modified.lua +++ b/lua/nvim-tree/modified.lua @@ -26,10 +26,7 @@ end ---@param node table ---@return boolean function M.is_modified(node) - return M.config.enable - and M._record[node.absolute_path] - and (not node.nodes or M.config.show_on_dirs) - and (not node.open or M.config.show_on_open_dirs) + return M.config.enable and M._record[node.absolute_path] and (not node.nodes or M.config.show_on_dirs) and (not node.open or M.config.show_on_open_dirs) end ---@param opts table diff --git a/lua/nvim-tree/renderer/components/git.lua b/lua/nvim-tree/renderer/components/git.lua index 977031fd945..468a9ee5f23 100644 --- a/lua/nvim-tree/renderer/components/git.lua +++ b/lua/nvim-tree/renderer/components/git.lua @@ -94,11 +94,7 @@ end local function nil_() end local function warn_status(git_status) - notify.warn( - 'Unrecognized git state "' - .. git_status - .. '". Please open up an issue on https://github.com/nvim-tree/nvim-tree.lua/issues with this message.' - ) + notify.warn('Unrecognized git state "' .. git_status .. '". Please open up an issue on https://github.com/nvim-tree/nvim-tree.lua/issues with this message.') end ---@param node table diff --git a/lua/nvim-tree/watcher.lua b/lua/nvim-tree/watcher.lua index efa5246963e..d9de19f945e 100644 --- a/lua/nvim-tree/watcher.lua +++ b/lua/nvim-tree/watcher.lua @@ -75,10 +75,7 @@ function Event:start() if rc ~= 0 then local warning = string.format("Could not start the fs_event watcher for path %s : %s", self._path, name) if name == "EMFILE" then - M.disable_watchers( - warning, - "Please see https://github.com/nvim-tree/nvim-tree.lua/wiki/Troubleshooting#could-not-start-fs_event-for-path--emfile" - ) + M.disable_watchers(warning, "Please see https://github.com/nvim-tree/nvim-tree.lua/wiki/Troubleshooting#could-not-start-fs_event-for-path--emfile") else notify.warn(warning) end