1

Support more options, better wrapping

This commit is contained in:
Alex Yatskov 2024-12-31 10:20:43 -08:00
parent a64cac9be8
commit 68a581f12b
3 changed files with 18 additions and 7 deletions

View File

@ -6,7 +6,6 @@ local options_current = {
comma_last = false, comma_last = false,
comma_prefix = false, comma_prefix = false,
comma_prefix_indent = false, comma_prefix_indent = false,
line_max = 32,
}, },
go = { go = {
comma_last = true, comma_last = true,

View File

@ -93,10 +93,9 @@ end
function Param:is_wrapped() function Param:is_wrapped()
local previous_param = self:get_previous() local previous_param = self:get_previous()
if previous_param then if previous_param then
-- print(get_param_stop_row(previous_param), get_param_start_row(self))
return get_param_stop_row(previous_param) ~= get_param_start_row(self) return get_param_stop_row(previous_param) ~= get_param_start_row(self)
else else
return false return self.range.start_cursor.row ~= get_param_start_row(self)
end end
end end

View File

@ -147,12 +147,25 @@ function Range:write(builder, wrapped)
builder:push_indent() builder:push_indent()
for i, param in ipairs(self.params) do for i, param in ipairs(self.params) do
param:write(builder) local is_first_param = i == 1
local is_last_param = i == #self.params local is_last_param = i == #self.params
if not is_last_param or self:query_option('comma_last') then
builder:write(',') if self:query_option('comma_prefix') then
if is_first_param then
if self:query_option('comma_prefix_indent') then
builder:write(' ')
end
else
builder:write(', ')
end
param:write(builder)
else
param:write(builder)
if not is_last_param or self:query_option('comma_last') then
builder:write(',')
end
end end
if not is_last_param then if not is_last_param then
builder:endline() builder:endline()
end end