From d50ed9858cf503bf8afb4c740c8b228f36ace734 Mon Sep 17 00:00:00 2001 From: Dominik Polakovics Date: Tue, 28 Oct 2025 14:10:04 +0100 Subject: [PATCH] fix: nvim sops, remove lsp --- hosts/nb/modules/development/nvim/config/sops.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hosts/nb/modules/development/nvim/config/sops.lua b/hosts/nb/modules/development/nvim/config/sops.lua index 9fae204..0194f3f 100644 --- a/hosts/nb/modules/development/nvim/config/sops.lua +++ b/hosts/nb/modules/development/nvim/config/sops.lua @@ -29,6 +29,15 @@ local function is_secrets_file(filepath) return false end +-- Helper function to detach all LSP clients from a buffer +-- This prevents LSP sync errors when SOPS replaces the entire buffer content +local function detach_lsp_clients(bufnr) + local clients = vim.lsp.get_active_clients({ bufnr = bufnr }) + for _, client in ipairs(clients) do + vim.lsp.buf_detach_client(bufnr, client.id) + end +end + -- Set filetype before reading to enable syntax highlighting vim.api.nvim_create_autocmd("BufReadPre", { group = sops_group, @@ -107,6 +116,9 @@ vim.api.nvim_create_autocmd("BufReadPost", { -- Ensure filetype is set to yaml for syntax highlighting vim.bo.filetype = "yaml" + -- Detach LSP clients to prevent sync errors when buffer content is replaced + detach_lsp_clients(0) + vim.notify("SOPS: File decrypted successfully", vim.log.levels.INFO) else vim.notify("SOPS: Failed to decrypt file: " .. result, vim.log.levels.ERROR) @@ -203,6 +215,9 @@ vim.api.nvim_create_autocmd("BufWriteCmd", { -- Restore cursor position pcall(vim.api.nvim_win_set_cursor, 0, cursor_pos) + + -- Detach LSP clients to prevent sync errors when buffer content is replaced + detach_lsp_clients(0) else vim.notify("SOPS: Could not re-decrypt after save. Buffer may show encrypted content.", vim.log.levels.WARN) end