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,5 +1,5 @@
local uv = vim.loop
local utils = require'nvim-tree.utils'
local utils = require "nvim-tree.utils"
local Runner = {}
Runner.__index = Runner
@@ -7,22 +7,22 @@ Runner.__index = Runner
function Runner:_parse_status_output(line)
local status = line:sub(1, 2)
-- removing `"` when git is returning special file status containing spaces
local path = line:sub(4, -2):gsub('^"', ''):gsub('"$', '')
local path = line:sub(4, -2):gsub('^"', ""):gsub('"$', "")
-- replacing slashes if on windows
if vim.fn.has('win32') == 1 then
path = path:gsub('/', '\\')
if vim.fn.has "win32" == 1 then
path = path:gsub("/", "\\")
end
if #status > 0 and #path > 0 then
self.output[utils.path_remove_trailing(utils.path_join({self.project_root,path}))] = status
self.output[utils.path_remove_trailing(utils.path_join { self.project_root, path })] = status
end
return #line
end
function Runner:_handle_incoming_data(prev_output, incoming)
if incoming and utils.str_find(incoming, '\n') then
local prev = prev_output..incoming
if incoming and utils.str_find(incoming, "\n") then
local prev = prev_output .. incoming
local i = 1
for line in prev:gmatch('[^\n]*\n') do
for line in prev:gmatch "[^\n]*\n" do
i = i + self:_parse_status_output(line)
end
@@ -30,10 +30,10 @@ function Runner:_handle_incoming_data(prev_output, incoming)
end
if incoming then
return prev_output..incoming
return prev_output .. incoming
end
for line in prev_output:gmatch('[^\n]*\n') do
for line in prev_output:gmatch "[^\n]*\n" do
self._parse_status_output(line)
end
@@ -41,10 +41,10 @@ function Runner:_handle_incoming_data(prev_output, incoming)
end
function Runner:_getopts(stdout_handle)
local untracked = self.list_untracked and '-u' or nil
local ignored = (self.list_untracked and self.list_ignored) and '--ignored=matching' or '--ignored=no'
local untracked = self.list_untracked and "-u" or nil
local ignored = (self.list_untracked and self.list_ignored) and "--ignored=matching" or "--ignored=no"
return {
args = {"--no-optional-locks", "status", "--porcelain=v1", ignored, untracked},
args = { "--no-optional-locks", "status", "--porcelain=v1", ignored, untracked },
cwd = self.project_root,
stdio = { nil, stdout_handle, nil },
}
@@ -74,14 +74,24 @@ function Runner:_run_git_job()
handle, pid = uv.spawn(
"git",
self:_getopts(stdout),
vim.schedule_wrap(function() on_finish() end)
vim.schedule_wrap(function()
on_finish()
end)
)
timer:start(self.timeout, 0, vim.schedule_wrap(function() on_finish() end))
timer:start(
self.timeout,
0,
vim.schedule_wrap(function()
on_finish()
end)
)
local output_leftover = ''
local output_leftover = ""
local function manage_output(err, data)
if err then return end
if err then
return
end
output_leftover = self:_handle_incoming_data(output_leftover, data)
end
@@ -89,7 +99,10 @@ function Runner:_run_git_job()
end
function Runner:_wait()
while not vim.wait(30, function() return self._done end, 30) do end
while not vim.wait(30, function()
return self._done
end, 30) do
end
end
-- This module runs a git process, which will be killed if it takes more than timeout which defaults to 400ms
@@ -100,7 +113,7 @@ function Runner.run(opts)
list_ignored = opts.list_ignored,
timeout = opts.timeout or 400,
output = {},
_done = false
_done = false,
}, Runner)
self:_run_git_job()