Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
90 lines
1.9 KiB
Lua
90 lines
1.9 KiB
Lua
local M = {}
|
|
|
|
local jobid = -1
|
|
|
|
local job = require('spacevim.api.job')
|
|
local util = require('format.util')
|
|
|
|
local stdout = {}
|
|
local stderr = {}
|
|
local current_task
|
|
|
|
local function on_stdout(id, data)
|
|
for _, v in ipairs(data) do
|
|
table.insert(stdout, v)
|
|
end
|
|
end
|
|
|
|
local function on_stderr(id, data)
|
|
for _, v in ipairs(data) do
|
|
table.insert(stderr, v)
|
|
end
|
|
end
|
|
|
|
local function on_exit(id, code, single)
|
|
util.info(
|
|
'formatter: '
|
|
.. (current_task.formatter.name or current_task.formatter.exe)
|
|
.. ' exit code:'
|
|
.. code
|
|
.. ' single:'
|
|
.. single
|
|
)
|
|
if code == 0 and single == 0 then
|
|
local formatted_context
|
|
if current_task.formatter.use_stderr then
|
|
formatted_context = stderr
|
|
else
|
|
formatted_context = stdout
|
|
end
|
|
if table.concat(formatted_context, '\n') == table.concat(current_task.stdin, '\n') then
|
|
util.msg('no necessary changes')
|
|
else
|
|
util.msg((current_task.formatter.name or current_task.formatter.exe) .. ' formatted buffer')
|
|
vim.api.nvim_buf_set_lines(
|
|
current_task.bufnr,
|
|
current_task.start_line,
|
|
current_task.end_line,
|
|
false,
|
|
formatted_context
|
|
)
|
|
end
|
|
else
|
|
util.msg('formatter ' .. current_task.formatter.exe .. ' failed to run')
|
|
end
|
|
|
|
jobid = -1
|
|
end
|
|
|
|
function M.run(task)
|
|
if jobid > 0 then
|
|
util.msg('previous formatting command has not ended')
|
|
return
|
|
end
|
|
|
|
util.info('running formatter: ' .. task.formatter.exe)
|
|
|
|
local cmd = { task.formatter.exe }
|
|
for _, v in ipairs(task.formatter.args) do
|
|
table.insert(cmd, v)
|
|
end
|
|
stdout = {}
|
|
stderr = {}
|
|
current_task = task
|
|
jobid = job.start(cmd, {
|
|
on_stdout = on_stdout,
|
|
on_stderr = on_stderr,
|
|
on_exit = on_exit,
|
|
})
|
|
|
|
if jobid == -1 then
|
|
return util.msg('formatter is not executable: ' .. task.formatter.exe)
|
|
end
|
|
|
|
if task.formatter.stdin then
|
|
job.send(jobid, task.stdin)
|
|
job.send(jobid, nil)
|
|
end
|
|
end
|
|
return M
|