chore: add stylua to format the codebase, and run on CI (#1055)

This commit is contained in:
Kiyan
2022-03-06 17:33:30 +01:00
committed by GitHub
parent 76d181d480
commit 0816064a8b
43 changed files with 871 additions and 732 deletions

View File

@@ -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]