fix: nvim sops, remove lsp

This commit is contained in:
2025-10-28 14:10:04 +01:00
parent 7af4b6a5d1
commit d50ed9858c

View File

@@ -29,6 +29,15 @@ local function is_secrets_file(filepath)
return false return false
end 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 -- Set filetype before reading to enable syntax highlighting
vim.api.nvim_create_autocmd("BufReadPre", { vim.api.nvim_create_autocmd("BufReadPre", {
group = sops_group, group = sops_group,
@@ -107,6 +116,9 @@ vim.api.nvim_create_autocmd("BufReadPost", {
-- Ensure filetype is set to yaml for syntax highlighting -- Ensure filetype is set to yaml for syntax highlighting
vim.bo.filetype = "yaml" 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) vim.notify("SOPS: File decrypted successfully", vim.log.levels.INFO)
else else
vim.notify("SOPS: Failed to decrypt file: " .. result, vim.log.levels.ERROR) 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 -- Restore cursor position
pcall(vim.api.nvim_win_set_cursor, 0, cursor_pos) 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 else
vim.notify("SOPS: Could not re-decrypt after save. Buffer may show encrypted content.", vim.log.levels.WARN) vim.notify("SOPS: Could not re-decrypt after save. Buffer may show encrypted content.", vim.log.levels.WARN)
end end