diff --git a/lua/argonaut/options.lua b/lua/argonaut/options.lua index b89788d..e7a9d0e 100644 --- a/lua/argonaut/options.lua +++ b/lua/argonaut/options.lua @@ -6,11 +6,13 @@ local options_current = { comma_last = false, comma_prefix = false, comma_prefix_indent = false, - line_max = 32, }, go = { comma_last = true, }, + lua = { + comma_last = true, + }, } local function setup(opt) diff --git a/lua/argonaut/param.lua b/lua/argonaut/param.lua index 86c283d..8aea334 100644 --- a/lua/argonaut/param.lua +++ b/lua/argonaut/param.lua @@ -5,6 +5,24 @@ local function is_empty_cell(cell) return cell.type == 'cursor' and not cell.value:get_value():match('%S') end +local function get_param_start_row(param) + local cell = param.cells[1] + if cell.type == 'range' then + return cell.value.start_cursor.row + elseif cell.type == 'cursor' then + return cell.value.row + end +end + +local function get_param_stop_row(param) + local cell = param.cells[#param.cells] + if cell.type == 'range' then + return cell.value.stop_cursor.row + elseif cell.type == 'cursor' then + return cell.value.row + end +end + function Param.new(range, index, cells) local param = { range = range, @@ -72,6 +90,21 @@ function Param:write(builder, wrapped) end end +function Param:is_wrapped() + local previous_param = self:get_previous() + if previous_param then + return get_param_stop_row(previous_param) ~= get_param_start_row(self) + else + return self.range.start_cursor.row ~= get_param_start_row(self) + end +end + +function Param:get_previous() + if self.index > 1 then + return self.range.params[self.index-1] + end +end + function Param:find_index_begin() for i = 1, #self.cells do if not is_empty_cell(self.cells[i]) then diff --git a/lua/argonaut/range.lua b/lua/argonaut/range.lua index 20047be..f5302ab 100644 --- a/lua/argonaut/range.lua +++ b/lua/argonaut/range.lua @@ -147,12 +147,25 @@ function Range:write(builder, wrapped) builder:push_indent() for i, param in ipairs(self.params) do - param:write(builder) - + local is_first_param = i == 1 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 + if not is_last_param then builder:endline() end @@ -206,7 +219,12 @@ function Range:query_option(name) end function Range:is_wrapped() - return self.start_cursor.row ~= self.stop_cursor.row + for _, param in ipairs(self.params) do + if param:is_wrapped() then + return true + end + end + return false end function Range.__lt(range_1, range_2)