1

Add additional information to params

This commit is contained in:
Alex Yatskov 2023-02-20 15:54:19 -08:00
parent 28ac806c9c
commit 2ddae6c52c

View File

@ -160,12 +160,26 @@ local function parse_brace_range(brace_range)
local last_line = vim.fn.getline(brace_range.row2) local last_line = vim.fn.getline(brace_range.row2)
brace_range.suffix = last_line:sub(brace_range.col2) brace_range.suffix = last_line:sub(brace_range.col2)
local brace_range_param = '' local brace_range_param = nil
local flush_brace_range_param = function() local flush_brace_range_param = function()
if #brace_range_param > 0 then if brace_range_param then
brace_range_param = string.gsub(brace_range_param , '^%s*(.-)%s*$', '%1') brace_range_param.text = string.gsub(brace_range_param.text , '^%s*(.-)%s*$', '%1')
table.insert(brace_range.params, brace_range_param) table.insert(brace_range.params, brace_range_param)
brace_range_param = '' brace_range_param = nil
end
end
local update_brace_range_param = function(element)
if brace_range_param then
brace_range_param.text = brace_range_param.text .. element.char
brace_range_param.length = brace_range_param.length + 1
else
brace_range_param = {
text = element.char,
row = element.row,
col = element.col,
length = 1,
}
end end
end end
@ -198,28 +212,30 @@ local function parse_brace_range(brace_range)
end end
for col = col1, col2 do for col = col1, col2 do
local c = line:sub(col, col) local char = line:sub(col, col)
assert(#c > 0) assert(#char > 0)
if lead_padding then if lead_padding then
if c:match('%s') then if char:match('%s') then
if pad_newline and col == col1 then if pad_newline and col == col1 then
c = ' ' char = ' '
else else
c = nil char = nil
end end
else else
lead_padding = false lead_padding = false
end end
end end
if c then if char then
table.insert(brace_range_elements, { table.insert(brace_range_elements, {
char = c, row = row,
col = col,
char = char,
literal = is_string_literal({row = row, col = col}), literal = is_string_literal({row = row, col = col}),
}) })
if c == ',' then if char == ',' then
pad_newline = true pad_newline = true
else else
pad_newline = false pad_newline = false
@ -240,7 +256,7 @@ local function parse_brace_range(brace_range)
end end
if append then if append then
brace_range_param = brace_range_param .. brace_range_element.char update_brace_range_param(brace_range_element)
end end
end end
@ -257,7 +273,7 @@ local function wrap_brace_range(brace_range)
for i, param in ipairs(brace_range.params) do for i, param in ipairs(brace_range.params) do
local on_last_row = i == #brace_range.params local on_last_row = i == #brace_range.params
local line = brace_range.indent .. param local line = brace_range.indent .. param.text
if config.tail_comma or not on_last_row then if config.tail_comma or not on_last_row then
line = line .. ',' line = line .. ','
end end
@ -280,7 +296,7 @@ end
local function unwrap_brace_range(brace_range) local function unwrap_brace_range(brace_range)
local line = brace_range.indent .. brace_range.prefix local line = brace_range.indent .. brace_range.prefix
for i, param in ipairs(brace_range.params) do for i, param in ipairs(brace_range.params) do
line = line .. param line = line .. param.text
if i < #brace_range.params then if i < #brace_range.params then
line = line .. ', ' line = line .. ', '
end end