fix(format): formatting
This commit is contained in:
+19
-11
@@ -30,7 +30,8 @@ local function notify(msg, title, level)
|
|||||||
and (info.source:sub(1, 1) == "@" and info.source:sub(2) or info.source)
|
and (info.source:sub(1, 1) == "@" and info.source:sub(2) or info.source)
|
||||||
or nil
|
or nil
|
||||||
local module = file and (get_module_path(file) or file) or nil
|
local module = file and (get_module_path(file) or file) or nil
|
||||||
title = module and module .. (info.name and info.name ~= "" and ":" .. info.name or "")
|
title = module
|
||||||
|
and module .. (info.name and info.name ~= "" and ":" .. info.name or "")
|
||||||
or nil
|
or nil
|
||||||
end
|
end
|
||||||
if title and not pcall(require, "notify") then
|
if title and not pcall(require, "notify") then
|
||||||
@@ -72,7 +73,8 @@ end
|
|||||||
function M.assert_any_installed(exes)
|
function M.assert_any_installed(exes)
|
||||||
assert(
|
assert(
|
||||||
M.any_installed(exes),
|
M.any_installed(exes),
|
||||||
"At least one of the following is required:\n" .. table.concat(exes, ", ")
|
"At least one of the following is required:\n"
|
||||||
|
.. table.concat(exes, ", ")
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -189,7 +191,8 @@ function M.format(opts)
|
|||||||
row_end, col_end = unpack(vim.fn.getpos("."), 2, 3)
|
row_end, col_end = unpack(vim.fn.getpos("."), 2, 3)
|
||||||
|
|
||||||
if row_start > row_end then
|
if row_start > row_end then
|
||||||
row_start, row_end, col_start, col_end = row_end, row_start, col_end, col_start
|
row_start, row_end, col_start, col_end =
|
||||||
|
row_end, row_start, col_end, col_start
|
||||||
end
|
end
|
||||||
|
|
||||||
if mode == "V" then
|
if mode == "V" then
|
||||||
@@ -254,15 +257,12 @@ function M.format(opts)
|
|||||||
not opts.ignore_ret and (resp.code ~= 0 or resp.signal ~= 0)
|
not opts.ignore_ret and (resp.code ~= 0 or resp.signal ~= 0)
|
||||||
or (opts.output ~= "stderr" and stderr)
|
or (opts.output ~= "stderr" and stderr)
|
||||||
then
|
then
|
||||||
local msg
|
local msg = ""
|
||||||
if stdout then
|
|
||||||
msg = "\n" .. stdout
|
|
||||||
end
|
|
||||||
if stderr then
|
if stderr then
|
||||||
msg = "\n" .. stderr
|
msg = ":\n" .. stderr
|
||||||
end
|
end
|
||||||
|
|
||||||
M.err(("Failed to format:%s"):format(msg or ""))
|
M.err(("Failed to format%s"):format(msg))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -271,14 +271,22 @@ function M.format(opts)
|
|||||||
local output_lines = vim.fn.split(output, "\n", true)
|
local output_lines = vim.fn.split(output, "\n", true)
|
||||||
|
|
||||||
if opts.only_selection then
|
if opts.only_selection then
|
||||||
vim.api.nvim_buf_set_lines(0, row_start - 1, row_end, false, output_lines)
|
vim.api.nvim_buf_set_lines(
|
||||||
|
0,
|
||||||
|
row_start - 1,
|
||||||
|
row_end,
|
||||||
|
false,
|
||||||
|
output_lines
|
||||||
|
)
|
||||||
else
|
else
|
||||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, output_lines)
|
vim.api.nvim_buf_set_lines(0, 0, -1, false, output_lines)
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts.auto_indent then
|
if opts.auto_indent then
|
||||||
if is_visual then
|
if is_visual then
|
||||||
vim.api.nvim_command(("%d,%dnormal! =="):format(row_start, row_start + #output_lines))
|
vim.api.nvim_command(
|
||||||
|
("%d,%dnormal! =="):format(row_start, row_start + #output_lines)
|
||||||
|
)
|
||||||
else
|
else
|
||||||
vim.api.nvim_command("normal! gg=G")
|
vim.api.nvim_command("normal! gg=G")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user