fix: nvim sops, remove lsp
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user