1
This commit is contained in:
Alex Yatskov 2024-04-24 22:17:50 -07:00
parent 6713b591b0
commit 47f1d2d2c3

View File

@ -297,9 +297,9 @@ end
local WrapContext = {} local WrapContext = {}
function WrapContext.new(opts) function WrapContext.new(opt)
local wrap_context = { local wrap_context = {
opts = opts, opt = opt,
indent = '', indent = '',
prefix = '', prefix = '',
suffix = '', suffix = '',
@ -351,40 +351,45 @@ function WrapContext:unwrap()
self.indent .. self.prefix self.indent .. self.prefix
) )
local cursor = nil
local row = self.range.start.row local row = self.range.start.row
for i, param in ipairs(self.params.parsed) do for i, param in ipairs(self.params.parsed) do
local on_last_param = i == #self.params.parsed local first_param = i == 1
local last_param = i == #self.params.parsed
local line = self.indent .. param.text local line = ''
if self.opts.tail_comma or not on_last_param then if self.opt.comma_first then
line = line .. ',' line = line .. self.indent .. self.opt.line_prefix
if not first_param then
line = line .. ', '
end
line = line .. param.text
else
line = line .. self.indent .. self.opt.line_prefix .. param.text
if not last_param or self.opt.tail_comma then
line = line .. ','
end
end end
if on_last_param and not self.opts.wrap_closing_brace then if last_param and not self.opt.wrap_closing_brace then
line = line .. self.suffix line = line .. self.suffix
end end
vim.fn.append(row, line) vim.fn.append(row, line)
vim.fn.execute(string.format('%d>', row + 1)) vim.fn.execute(string.format('%d>', row + 1))
-- if param.offset then if first_param and self.opt.comma_first_indent then
-- cursor = cursor local prev_shiftwidth = vim.o.shiftwidth
-- cursor.col = cursor.col + param.offset vim.o.shiftwidth = prev_shiftwidth - 2
-- cursor.row = row + 1 vim.fn.execute(string.format('%d>', row + 1))
-- end vim.o.shiftwidth = prev_shiftwidth
end
row = row + 1 row = row + 1
end end
if self.opts.wrap_closing_brace then if self.opt.wrap_closing_brace then
vim.fn.append(row, self.indent .. self.suffix) vim.fn.append(row, self.indent .. self.suffix)
end end
if cursor then
cursor:set_current()
end
end end
function WrapContext:toggle() function WrapContext:toggle()