feat(format): remove in-place formatting support
This commit is contained in:
+4
-19
@@ -154,7 +154,6 @@ end
|
|||||||
--- * %col_end% - last column position of selection
|
--- * %col_end% - last column position of selection
|
||||||
--- * %byte_start% - byte count of first cell in selection
|
--- * %byte_start% - byte count of first cell in selection
|
||||||
--- * %byte_end% - byte count of last cell in selection
|
--- * %byte_end% - byte count of last cell in selection
|
||||||
---@field stdin? boolean Pass text to stdin. Assumes in-place formatting on False. False by default.
|
|
||||||
---@field stdout? boolean Use stdout as the result. False by default.
|
---@field stdout? boolean Use stdout as the result. False by default.
|
||||||
---@field stderr? boolean Use stderr as the result. False by default.
|
---@field stderr? boolean Use stderr as the result. False by default.
|
||||||
---@field auto_indent? boolean Perform auto indent on formatted range. False by default.
|
---@field auto_indent? boolean Perform auto indent on formatted range. False by default.
|
||||||
@@ -165,18 +164,14 @@ end
|
|||||||
function M.format(opts)
|
function M.format(opts)
|
||||||
opts = {
|
opts = {
|
||||||
cmd = opts.cmd,
|
cmd = opts.cmd,
|
||||||
stdin = opts.stdin or false,
|
|
||||||
stdout = opts.stdout or false,
|
stdout = opts.stdout or false,
|
||||||
stderr = opts.stderr or false,
|
stderr = opts.stderr or false,
|
||||||
auto_indent = opts.auto_indent or false,
|
auto_indent = opts.auto_indent or false,
|
||||||
only_selection = opts.only_selection or false,
|
only_selection = opts.only_selection or false,
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.stdin and not (opts.stdout or opts.stderr) then
|
if not opts.stdout and not opts.stderr then
|
||||||
M.err("`stdin` requires that one of `stdout` or `stderr` is set")
|
M.err("one of `stdout` or `stderr` must be set")
|
||||||
return
|
|
||||||
elseif (opts.only_selection or opts.stdout or opts.stderr) and not opts.stdin then
|
|
||||||
M.err("`stdout`, `stderr` and `only_selection` requires `stdin` to be set")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -206,16 +201,10 @@ function M.format(opts)
|
|||||||
local input
|
local input
|
||||||
if opts.only_selection then
|
if opts.only_selection then
|
||||||
input = vim.api.nvim_buf_get_lines(0, row_start - 1, row_end, false)
|
input = vim.api.nvim_buf_get_lines(0, row_start - 1, row_end, false)
|
||||||
elseif opts.stdin then
|
else
|
||||||
input = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
input = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not opts.stdin then
|
|
||||||
vim.api.nvim_buf_call(0, function()
|
|
||||||
vim.cmd("silent write")
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
for i, arg in ipairs(opts.cmd) do
|
for i, arg in ipairs(opts.cmd) do
|
||||||
arg = arg:gsub("%%file%%", file)
|
arg = arg:gsub("%%file%%", file)
|
||||||
arg = arg:gsub("%%filename%%", filename)
|
arg = arg:gsub("%%filename%%", filename)
|
||||||
@@ -232,7 +221,7 @@ function M.format(opts)
|
|||||||
|
|
||||||
local stdout, stderr, err
|
local stdout, stderr, err
|
||||||
local resp = vim.system(opts.cmd, {
|
local resp = vim.system(opts.cmd, {
|
||||||
stdin = opts.stdin and input or nil,
|
stdin = input,
|
||||||
stdout = opts.stdout and function(e, data)
|
stdout = opts.stdout and function(e, data)
|
||||||
if data then
|
if data then
|
||||||
stdout = stdout and stdout .. data or data
|
stdout = stdout and stdout .. data or data
|
||||||
@@ -263,9 +252,6 @@ function M.format(opts)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if not opts.stdin then
|
|
||||||
vim.api.nvim_buf_call(0, vim.cmd.edit)
|
|
||||||
else
|
|
||||||
local output
|
local output
|
||||||
if opts.stdout then
|
if opts.stdout then
|
||||||
output = stdout or ""
|
output = stdout or ""
|
||||||
@@ -293,7 +279,6 @@ function M.format(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
--- Check if `val` is a list of type `t` (if given)
|
--- Check if `val` is a list of type `t` (if given)
|
||||||
---@param val any
|
---@param val any
|
||||||
|
|||||||
Reference in New Issue
Block a user