chore: add stylua to format the codebase, and run on CI (#1055)
This commit is contained in:
@@ -3,9 +3,7 @@ local uv = vim.loop
|
||||
local M = {}
|
||||
|
||||
function M.has_one_child_folder(node)
|
||||
return #node.nodes == 1
|
||||
and node.nodes[1].nodes
|
||||
and uv.fs_access(node.nodes[1].absolute_path, 'R')
|
||||
return #node.nodes == 1 and node.nodes[1].nodes and uv.fs_access(node.nodes[1].absolute_path, "R")
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
local api = vim.api
|
||||
local uv = vim.loop
|
||||
|
||||
local utils = require'nvim-tree.utils'
|
||||
local builders = require'nvim-tree.explorer.node-builders'
|
||||
local common = require'nvim-tree.explorer.common'
|
||||
local sorters = require"nvim-tree.explorer.sorters"
|
||||
local filters = require"nvim-tree.explorer.filters"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local builders = require "nvim-tree.explorer.node-builders"
|
||||
local common = require "nvim-tree.explorer.common"
|
||||
local sorters = require "nvim-tree.explorer.sorters"
|
||||
local filters = require "nvim-tree.explorer.filters"
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -14,19 +14,21 @@ local function get_type_from(type_, cwd)
|
||||
end
|
||||
|
||||
local function populate_children(handle, cwd, node, status)
|
||||
local node_ignored = node.git_status == '!!'
|
||||
local node_ignored = node.git_status == "!!"
|
||||
while true do
|
||||
local name, t = uv.fs_scandir_next(handle)
|
||||
if not name then break end
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
|
||||
local abs = utils.path_join({cwd, name})
|
||||
local abs = utils.path_join { cwd, name }
|
||||
t = get_type_from(t, abs)
|
||||
if not filters.should_ignore(abs) and not filters.should_ignore_git(abs, status.files) then
|
||||
if t == 'directory' and uv.fs_access(abs, 'R') then
|
||||
if t == "directory" and uv.fs_access(abs, "R") then
|
||||
table.insert(node.nodes, builders.folder(abs, name, status, node_ignored))
|
||||
elseif t == 'file' then
|
||||
elseif t == "file" then
|
||||
table.insert(node.nodes, builders.file(abs, name, status, node_ignored))
|
||||
elseif t == 'link' then
|
||||
elseif t == "link" then
|
||||
local link = builders.link(abs, name, status, node_ignored)
|
||||
if link.link_to ~= nil then
|
||||
table.insert(node.nodes, link)
|
||||
@@ -38,7 +40,7 @@ end
|
||||
|
||||
local function get_dir_handle(cwd)
|
||||
local handle = uv.fs_scandir(cwd)
|
||||
if type(handle) == 'string' then
|
||||
if type(handle) == "string" then
|
||||
api.nvim_err_writeln(handle)
|
||||
return
|
||||
end
|
||||
@@ -48,7 +50,9 @@ end
|
||||
function M.explore(node, status)
|
||||
local cwd = node.cwd or node.link_to or node.absolute_path
|
||||
local handle = get_dir_handle(cwd)
|
||||
if not handle then return end
|
||||
if not handle then
|
||||
return
|
||||
end
|
||||
|
||||
populate_children(handle, cwd, node, status)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local utils = require'nvim-tree.utils'
|
||||
local utils = require "nvim-tree.utils"
|
||||
|
||||
local M = {
|
||||
ignore_list = {},
|
||||
@@ -25,7 +25,7 @@ function M.should_ignore(path)
|
||||
end
|
||||
|
||||
if M.config.filter_dotfiles then
|
||||
if basename:sub(1, 1) == '.' then
|
||||
if basename:sub(1, 1) == "." then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -39,9 +39,9 @@ function M.should_ignore(path)
|
||||
return true
|
||||
end
|
||||
|
||||
local idx = path:match(".+()%.[^.]+$")
|
||||
local idx = path:match ".+()%.[^.]+$"
|
||||
if idx then
|
||||
if M.ignore_list['*'..string.sub(path, idx)] == true then
|
||||
if M.ignore_list["*" .. string.sub(path, idx)] == true then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -51,7 +51,7 @@ end
|
||||
|
||||
function M.should_ignore_git(path, status)
|
||||
return M.config.filter_ignored
|
||||
and (M.config.filter_git_ignored and status and status[path] == '!!')
|
||||
and (M.config.filter_git_ignored and status and status[path] == "!!")
|
||||
and not is_excluded(path)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
local uv = vim.loop
|
||||
|
||||
local git = require"nvim-tree.git"
|
||||
local git = require "nvim-tree.git"
|
||||
|
||||
local M = {}
|
||||
|
||||
M.explore = require"nvim-tree.explorer.explore".explore
|
||||
M.reload = require"nvim-tree.explorer.reload".reload
|
||||
M.explore = require("nvim-tree.explorer.explore").explore
|
||||
M.reload = require("nvim-tree.explorer.reload").reload
|
||||
|
||||
local Explorer = {}
|
||||
Explorer.__index = Explorer
|
||||
@@ -14,7 +14,7 @@ function Explorer.new(cwd)
|
||||
cwd = uv.fs_realpath(cwd or uv.cwd())
|
||||
local explorer = setmetatable({
|
||||
cwd = cwd,
|
||||
nodes = {}
|
||||
nodes = {},
|
||||
}, Explorer)
|
||||
explorer:_load(explorer)
|
||||
return explorer
|
||||
@@ -31,8 +31,8 @@ function Explorer:expand(node)
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
require"nvim-tree.explorer.filters".setup(opts)
|
||||
require"nvim-tree.explorer.sorters".setup(opts)
|
||||
require("nvim-tree.explorer.filters").setup(opts)
|
||||
require("nvim-tree.explorer.sorters").setup(opts)
|
||||
end
|
||||
|
||||
M.Explorer = Explorer
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
local uv = vim.loop
|
||||
local utils = require'nvim-tree.utils'
|
||||
local utils = require "nvim-tree.utils"
|
||||
|
||||
local M = {
|
||||
is_windows = vim.fn.has('win32') == 1
|
||||
is_windows = vim.fn.has "win32" == 1,
|
||||
}
|
||||
|
||||
function M.get_dir_git_status(parent_ignored, status, absolute_path)
|
||||
if parent_ignored then
|
||||
return '!!'
|
||||
return "!!"
|
||||
end
|
||||
local dir_status = status.dirs and status.dirs[absolute_path]
|
||||
local file_status = status.files and status.files[absolute_path]
|
||||
@@ -15,7 +15,7 @@ function M.get_dir_git_status(parent_ignored, status, absolute_path)
|
||||
end
|
||||
|
||||
function M.get_git_status(parent_ignored, status, absolute_path)
|
||||
return parent_ignored and '!!' or status.files and status.files[absolute_path]
|
||||
return parent_ignored and "!!" or status.files and status.files[absolute_path]
|
||||
end
|
||||
|
||||
function M.folder(absolute_path, name, status, parent_ignored)
|
||||
@@ -38,7 +38,7 @@ local function is_executable(absolute_path, ext)
|
||||
if M.is_windows then
|
||||
return utils.is_windows_exe(ext)
|
||||
end
|
||||
return uv.fs_access(absolute_path, 'X')
|
||||
return uv.fs_access(absolute_path, "X")
|
||||
end
|
||||
|
||||
function M.file(absolute_path, name, status, parent_ignored)
|
||||
@@ -63,7 +63,7 @@ function M.link(absolute_path, name, status, parent_ignored)
|
||||
--- I dont know if this is needed, because in my understanding, there isnt hard links in windows, but just to be sure i changed it.
|
||||
local link_to = uv.fs_realpath(absolute_path)
|
||||
local open, nodes
|
||||
if (link_to ~= nil) and uv.fs_stat(link_to).type == 'directory' then
|
||||
if (link_to ~= nil) and uv.fs_stat(link_to).type == "directory" then
|
||||
open = false
|
||||
nodes = {}
|
||||
end
|
||||
@@ -71,7 +71,7 @@ function M.link(absolute_path, name, status, parent_ignored)
|
||||
return {
|
||||
absolute_path = absolute_path,
|
||||
git_status = M.get_git_status(parent_ignored, status, absolute_path),
|
||||
group_next = nil, -- If node is grouped, this points to the next child dir/link node
|
||||
group_next = nil, -- If node is grouped, this points to the next child dir/link node
|
||||
link_to = link_to,
|
||||
name = name,
|
||||
nodes = nodes,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
local api = vim.api
|
||||
local uv = vim.loop
|
||||
|
||||
local utils = require'nvim-tree.utils'
|
||||
local builders = require'nvim-tree.explorer.node-builders'
|
||||
local common = require'nvim-tree.explorer.common'
|
||||
local filters = require'nvim-tree.explorer.filters'
|
||||
local sorters = require'nvim-tree.explorer.sorters'
|
||||
local utils = require "nvim-tree.utils"
|
||||
local builders = require "nvim-tree.explorer.node-builders"
|
||||
local common = require "nvim-tree.explorer.common"
|
||||
local filters = require "nvim-tree.explorer.filters"
|
||||
local sorters = require "nvim-tree.explorer.sorters"
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -33,34 +33,36 @@ end
|
||||
function M.reload(node, status)
|
||||
local cwd = node.cwd or node.link_to or node.absolute_path
|
||||
local handle = uv.fs_scandir(cwd)
|
||||
if type(handle) == 'string' then
|
||||
if type(handle) == "string" then
|
||||
api.nvim_err_writeln(handle)
|
||||
return
|
||||
end
|
||||
|
||||
if node.group_next then
|
||||
node.nodes = {node.group_next}
|
||||
node.nodes = { node.group_next }
|
||||
node.group_next = nil
|
||||
end
|
||||
|
||||
local child_names = {}
|
||||
|
||||
local node_ignored = node.git_status == '!!'
|
||||
local node_ignored = node.git_status == "!!"
|
||||
local nodes_by_path = key_by(node.nodes, "absolute_path")
|
||||
while true do
|
||||
local name, t = uv.fs_scandir_next(handle)
|
||||
if not name then break end
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
|
||||
local abs = utils.path_join({cwd, name})
|
||||
local abs = utils.path_join { cwd, name }
|
||||
t = t or (uv.fs_stat(abs) or {}).type
|
||||
if not filters.should_ignore(abs) and not filters.should_ignore_git(abs, status.files) then
|
||||
child_names[abs] = true
|
||||
if not nodes_by_path[abs] then
|
||||
if t == 'directory' and uv.fs_access(abs, 'R') then
|
||||
if t == "directory" and uv.fs_access(abs, "R") then
|
||||
table.insert(node.nodes, builders.folder(abs, name, status, node_ignored))
|
||||
elseif t == 'file' then
|
||||
elseif t == "file" then
|
||||
table.insert(node.nodes, builders.file(abs, name, status, node_ignored))
|
||||
elseif t == 'link' then
|
||||
elseif t == "link" then
|
||||
local link = builders.link(abs, name, status, node_ignored)
|
||||
if link.link_to ~= nil then
|
||||
table.insert(node.nodes, link)
|
||||
@@ -72,10 +74,10 @@ function M.reload(node, status)
|
||||
|
||||
node.nodes = vim.tbl_map(
|
||||
update_status(nodes_by_path, node_ignored, status),
|
||||
vim.tbl_filter(
|
||||
function(n) return child_names[n.absolute_path] end,
|
||||
node.nodes
|
||||
))
|
||||
vim.tbl_filter(function(n)
|
||||
return child_names[n.absolute_path]
|
||||
end, node.nodes)
|
||||
)
|
||||
|
||||
local is_root = node.cwd ~= nil
|
||||
local child_folder_only = common.has_one_child_folder(node) and node.nodes[1]
|
||||
|
||||
@@ -26,7 +26,7 @@ local function merge(t, first, mid, last, comparator)
|
||||
local j = 1
|
||||
local k = first
|
||||
|
||||
while (i <= n1 and j <= n2) do
|
||||
while i <= n1 and j <= n2 do
|
||||
if comparator(ls[i], rs[j]) then
|
||||
t[k] = ls[i]
|
||||
i = i + 1
|
||||
@@ -51,7 +51,9 @@ local function merge(t, first, mid, last, comparator)
|
||||
end
|
||||
|
||||
local function split_merge(t, first, last, comparator)
|
||||
if (last - first) < 1 then return end
|
||||
if (last - first) < 1 then
|
||||
return
|
||||
end
|
||||
|
||||
local mid = math.floor((first + last) / 2)
|
||||
|
||||
@@ -65,7 +67,7 @@ end
|
||||
---@param comparator function|nil
|
||||
function M.merge_sort(t, comparator)
|
||||
if not comparator then
|
||||
comparator = function (left, right)
|
||||
comparator = function(left, right)
|
||||
return left < right
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user