From becf45d348c2b1d26a91546b97977df14e247409 Mon Sep 17 00:00:00 2001 From: Lazar Bulovan Date: Thu, 19 Feb 2026 11:17:59 +0100 Subject: [PATCH] fix: clear attr_toggle state after formatting When :LspSCLFormat is used, line numbers and positions change, but the attr_toggle module stores state based on old positions. This caused toggle/expand/collapse to not work after formatting. Now clears the attr_toggle buffer state after formatting so that users can collapse blocks fresh after formatting. --- lua/scl_lsp/init.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lua/scl_lsp/init.lua b/lua/scl_lsp/init.lua index 390ff32..5800d5f 100644 --- a/lua/scl_lsp/init.lua +++ b/lua/scl_lsp/init.lua @@ -36,6 +36,11 @@ function M.setup(opts) if opts.lsp and opts.lsp.formatting then vim.api.nvim_buf_create_user_command(b, "LspSCLFormat", function() vim.lsp.buf.format({ name = "scl_lsp" }) + -- Clear attr_toggle state since line positions may have changed + local ok, at = pcall(require, "scl.attr_toggle") + if ok then + at.clear_buffer_state(vim.api.nvim_get_current_buf()) + end end, {}) end end, @@ -53,6 +58,11 @@ function M.setup(opts) -- Create global format command (works on current buffer) vim.api.nvim_create_user_command("LspSCLFormat", function() vim.lsp.buf.format({ name = "scl_lsp" }) + -- Clear attr_toggle state since line positions may have changed + local ok, at = pcall(require, "scl.attr_toggle") + if ok then + at.clear_buffer_state(vim.api.nvim_get_current_buf()) + end end, {}) -- Start LSP for any existing scl buffers (handles lazy loading case)