From b0e0b6448d814ca8db2b036ef685566b0b07af00 Mon Sep 17 00:00:00 2001 From: n3oney Date: Fri, 12 May 2023 20:07:44 +0200 Subject: [PATCH] fix: re-work formatting code --- modules/lsp/config.nix | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/modules/lsp/config.nix b/modules/lsp/config.nix index 2bf2567..bcd69d4 100644 --- a/modules/lsp/config.nix +++ b/modules/lsp/config.nix @@ -36,20 +36,21 @@ in { end -- Enable formatting - format_callback = function(client, bufnr) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - if vim.g.formatsave then - if client.supports_method("textDocument/formatting") then - local params = require'vim.lsp.util'.make_formatting_params({}) - client.request('textDocument/formatting', params, nil, bufnr) + local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) - end - end - end - }) + format_callback = function(client, bufnr) + if vim.g.formatsave and client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ + bufnr = bufnr + }) + end, + }) + end end default_on_attach = function(client, bufnr)