feat: add interactive attribute block toggle with keybindings and commands
Add ability to expand/collapse SCL variable attribute blocks like {EXTERNALACCESSIBLE := 'false'} to {...}
Features:
- Per-variable collapse rules via collapseVariableRules option
- Interactive toggle with <Leader>xa keybinding
- Commands: SCLToggleAttrBlock, SCLExpandAllAttrBlocks, SCLCollapseAllAttrBlocks
- Keybindings: <Leader>xa (toggle), <Leader>xae (expand all), <Leader>xac (collapse all)
- Supports both formatter-collapsed and manually collapsed blocks
Also update AGENTS.md with new documentation and troubleshooting guide
This commit is contained in:
@@ -88,6 +88,9 @@ function M.setup(opts)
|
||||
|
||||
-- Multiline parameters feature
|
||||
M.setup_multiline_params()
|
||||
|
||||
-- Attribute block toggle feature
|
||||
M.setup_attr_toggle()
|
||||
end
|
||||
|
||||
function M.setup_multiline_params()
|
||||
@@ -171,6 +174,76 @@ function M.create_commands()
|
||||
vim.api.nvim_create_user_command("SCLShowVariables", function() M.show_variables() end, {})
|
||||
vim.api.nvim_create_user_command("SCLShowWorkspaceTypes", function() M.show_workspace_types() end, {})
|
||||
vim.api.nvim_create_user_command("SCLRescanWorkspaceTypes", function() M.rescan_workspace_types() end, {})
|
||||
|
||||
-- Attribute toggle commands
|
||||
vim.api.nvim_create_user_command("SCLToggleAttrBlock", function()
|
||||
local ok, at = pcall(require, "scl.attr_toggle")
|
||||
if ok then
|
||||
at.toggle_attr_block()
|
||||
else
|
||||
vim.notify("SCL: Failed to load attr_toggle module", vim.log.levels.ERROR)
|
||||
end
|
||||
end, {})
|
||||
vim.api.nvim_create_user_command("SCLExpandAllAttrBlocks", function()
|
||||
local ok, at = pcall(require, "scl.attr_toggle")
|
||||
if ok then
|
||||
at.expand_all_attr_blocks()
|
||||
else
|
||||
vim.notify("SCL: Failed to load attr_toggle module", vim.log.levels.ERROR)
|
||||
end
|
||||
end, {})
|
||||
vim.api.nvim_create_user_command("SCLCollapseAllAttrBlocks", function()
|
||||
local ok, at = pcall(require, "scl.attr_toggle")
|
||||
if ok then
|
||||
at.collapse_all_attr_blocks()
|
||||
else
|
||||
vim.notify("SCL: Failed to load attr_toggle module", vim.log.levels.ERROR)
|
||||
end
|
||||
end, {})
|
||||
end
|
||||
|
||||
function M.setup_attr_toggle()
|
||||
local at = require("scl.attr_toggle")
|
||||
at.setup()
|
||||
|
||||
local function setup_buffer_keymaps(bufnr)
|
||||
local opts = { buffer = bufnr, silent = true }
|
||||
local ft = vim.bo[bufnr].filetype
|
||||
|
||||
if ft ~= "scl" and ft ~= "udt" then
|
||||
return
|
||||
end
|
||||
|
||||
-- Toggle individual attribute block under cursor
|
||||
vim.keymap.set({ "n", "i" }, "<Leader>xa", function()
|
||||
at.toggle_attr_block()
|
||||
end, vim.tbl_extend("force", opts, { desc = "SCL: Toggle attribute block" }))
|
||||
|
||||
-- Expand all collapsed blocks
|
||||
vim.keymap.set("n", "<Leader>xae", function()
|
||||
at.expand_all_attr_blocks()
|
||||
end, vim.tbl_extend("force", opts, { desc = "SCL: Expand all attribute blocks" }))
|
||||
|
||||
-- Collapse all attribute blocks
|
||||
vim.keymap.set("n", "<Leader>xac", function()
|
||||
at.collapse_all_attr_blocks()
|
||||
end, vim.tbl_extend("force", opts, { desc = "SCL: Collapse all attribute blocks" }))
|
||||
end
|
||||
|
||||
-- Set up keybindings for SCL files only
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = { "scl", "udt" },
|
||||
callback = function(args)
|
||||
setup_buffer_keymaps(args.buf)
|
||||
end,
|
||||
})
|
||||
|
||||
-- Also check if there are already SCL buffers open
|
||||
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if vim.api.nvim_buf_is_loaded(bufnr) then
|
||||
setup_buffer_keymaps(bufnr)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user