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

@@ -2,33 +2,34 @@ local uv = vim.loop
local M = {
config = {
is_windows = vim.fn.has('win32') == 1 or vim.fn.has('win32unix') == 1,
is_macos = vim.fn.has('mac') == 1 or vim.fn.has('macunix') == 1,
is_unix = vim.fn.has('unix') == 1,
}
is_windows = vim.fn.has "win32" == 1 or vim.fn.has "win32unix" == 1,
is_macos = vim.fn.has "mac" == 1 or vim.fn.has "macunix" == 1,
is_unix = vim.fn.has "unix" == 1,
},
}
function M.fn(node)
if not M.config.system_open.cmd then
require'nvim-tree.utils'.warn("Cannot open file with system application. Unrecognized platform.")
require("nvim-tree.utils").warn "Cannot open file with system application. Unrecognized platform."
return
end
local process = {
cmd = M.config.system_open.cmd,
args = M.config.system_open.args,
errors = '\n',
stderr = uv.new_pipe(false)
errors = "\n",
stderr = uv.new_pipe(false),
}
table.insert(process.args, node.link_to or node.absolute_path)
process.handle, process.pid = uv.spawn(process.cmd,
process.handle, process.pid = uv.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
process.errors = process.errors .. string.format('NvimTree system_open: return code %d.', code)
process.errors = process.errors .. string.format("NvimTree system_open: return code %d.", code)
error(process.errors)
end
end
@@ -38,14 +39,15 @@ function M.fn(node)
error("\n" .. process.pid .. "\nNvimTree system_open: failed to spawn process using '" .. process.cmd .. "'.")
return
end
uv.read_start(process.stderr,
function(err, data)
if err then return end
if data then process.errors = process.errors .. data end
uv.read_start(process.stderr, function(err, data)
if err then
return
end
)
if data then
process.errors = process.errors .. data
end
end)
uv.unref(process.handle)
end
function M.setup(opts)
@@ -55,12 +57,12 @@ function M.setup(opts)
if M.config.is_windows then
M.config.system_open = {
cmd = "cmd",
args = {'/c', 'start', '""'}
args = { "/c", "start", '""' },
}
elseif M.config.is_macos then
M.config.system_open.cmd = 'open'
M.config.system_open.cmd = "open"
elseif M.config.is_unix then
M.config.system_open.cmd = 'xdg-open'
M.config.system_open.cmd = "xdg-open"
end
end
end