1
This commit is contained in:
Alex Yatskov 2023-02-20 14:21:29 -08:00
parent 6fe2301c89
commit 7c84e7a940

View File

@ -8,6 +8,9 @@ local argonaut_configs = {
wrap_closing_brace = true, wrap_closing_brace = true,
comma_first = false, comma_first = false,
comma_first_indent = false, comma_first_indent = false,
},
go = {
tail_comma = true,
} }
} }
@ -72,7 +75,7 @@ local function is_string_literal(pos)
pos = get_cursor_pos() pos = get_cursor_pos()
end end
local syn_id = vim.fn.synID(pos.row, pos.col, false) local syn_id = vim.fn.synID(pos.row, pos.col, false)
local syn_attr = vim.fn.synIDattr(syn_id, 'name') local syn_attr = vim.fn.synIDattr(syn_id, 'name')
return syn_attr:find('String$') return syn_attr:find('String$')
@ -247,24 +250,32 @@ local function parse_brace_range(brace_range)
end end
local function wrap_brace_range(brace_range) local function wrap_brace_range(brace_range)
local config = get_config()
vim.fn.setline(brace_range.row1, brace_range.indent .. brace_range.prefix) vim.fn.setline(brace_range.row1, brace_range.indent .. brace_range.prefix)
local row = brace_range.row1 local row = brace_range.row1
for i, param in ipairs(brace_range.params) do for i, param in ipairs(brace_range.params) do
local last = i == #brace_range.params local on_last_row = i == #brace_range.params
local line = brace_range.indent .. param local line = brace_range.indent .. param
if not last then if config.tail_comma or not on_last_row then
line = line .. ',' line = line .. ','
end end
if on_last_row and not config.wrap_closing_brace then
line = line .. brace_range.suffix
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))
row = row + 1 row = row + 1
end end
vim.fn.append(row, brace_range.indent .. brace_range.suffix) if config.wrap_closing_brace then
vim.fn.append(row, brace_range.indent .. brace_range.suffix)
end
end end
local function unwrap_brace_range(brace_range) local function unwrap_brace_range(brace_range)
@ -278,11 +289,11 @@ local function unwrap_brace_range(brace_range)
line = line .. brace_range.suffix line = line .. brace_range.suffix
vim.fn.setline(brace_range.row1, line) vim.fn.setline(brace_range.row1, line)
vim.fn.execute(string.format('%d,%dd_', brace_range.row1 + 1, brace_range.row2), true) vim.fn.execute(string.format('%d,%dd_', brace_range.row1 + 1, brace_range.row2), true)
end end
local function reflow() local function reflow()
local brace_range = find_closest_brace_range({'(', '[', '{', '<'}) local brace_range = find_closest_brace_range({'(', '[', '{', '<'})
if brace_range then if brace_range then
parse_brace_range(brace_range) parse_brace_range(brace_range)
if brace_range.row1 == brace_range.row2 then if brace_range.row1 == brace_range.row2 then