feat: improve formatter and attribute block handling
- Format multi-line assignments with proper alignment - Format FB calls in multiline style with parameter alignment - Auto-expand collapsed attribute blocks before save - Rename command from LspSCLFormat to SCLFormat - Condense AGENTS.md and add testing section with reference project
This commit is contained in:
+27
-5
@@ -80,23 +80,24 @@ function M.toggle_attr_block()
|
||||
end
|
||||
|
||||
-- Expand all collapsed blocks in current buffer
|
||||
function M.expand_all_attr_blocks()
|
||||
function M.expand_all_attr_blocks(opts)
|
||||
opts = opts or {}
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||
local count = 0
|
||||
|
||||
if not buffer_attr_state[bufnr] then
|
||||
vim.notify("No collapsed blocks to expand", vim.log.levels.INFO)
|
||||
if not opts.silent then
|
||||
vim.notify("No collapsed blocks to expand", vim.log.levels.INFO)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
for state_key, state in pairs(buffer_attr_state[bufnr]) do
|
||||
if state.is_collapsed then
|
||||
-- state.line_num is 1-indexed, but nvim_buf_get_lines returns 0-indexed array
|
||||
local line = lines[state.line_num]
|
||||
|
||||
if line then
|
||||
-- Find the collapsed {...} and replace with expanded content
|
||||
local new_line = line:sub(1, state.start_col) .. state.expanded .. line:sub(state.start_col + 4)
|
||||
lines[state.line_num] = new_line
|
||||
state.is_collapsed = false
|
||||
@@ -106,7 +107,9 @@ function M.expand_all_attr_blocks()
|
||||
end
|
||||
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
vim.notify("Expanded " .. count .. " attribute block(s)", vim.log.levels.INFO)
|
||||
if not opts.silent and count > 0 then
|
||||
vim.notify("Expanded " .. count .. " attribute block(s)", vim.log.levels.INFO)
|
||||
end
|
||||
end
|
||||
|
||||
-- Helper to make a pattern case-insensitive
|
||||
@@ -193,6 +196,25 @@ end
|
||||
function M.setup()
|
||||
local augroup = vim.api.nvim_create_augroup("SCLAttrToggle", { clear = true })
|
||||
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = augroup,
|
||||
pattern = { "*.scl", "*.udt", "*.db" },
|
||||
callback = function(args)
|
||||
if buffer_attr_state[args.buf] then
|
||||
local has_collapsed = false
|
||||
for _, state in pairs(buffer_attr_state[args.buf]) do
|
||||
if state.is_collapsed then
|
||||
has_collapsed = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if has_collapsed then
|
||||
M.expand_all_attr_blocks({ silent = true })
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("BufUnload", {
|
||||
group = augroup,
|
||||
pattern = { "*.scl", "*.udt", "*.db" },
|
||||
|
||||
Reference in New Issue
Block a user