diff --git a/home-manager/neovim/lspconfig.lua b/home-manager/neovim/lspconfig.lua index ee5f769..5b79d43 100644 --- a/home-manager/neovim/lspconfig.lua +++ b/home-manager/neovim/lspconfig.lua @@ -5,6 +5,12 @@ local on_attach = function(client, bufnr) vim.keymap.set("n", key, command, { noremap = true, silent = true, buffer = bufnr }) end + local function format_buffer() + vim.lsp.buf.format({ timeout_ms = 3000, async = false, filter = function(formatter) + return formatter.name ~= "tsserver" and formatter.name ~= "volar" + end }) + end + local telescope = require("telescope.builtin") nnoremap("gD", vim.lsp.buf.declaration) @@ -15,25 +21,18 @@ local on_attach = function(client, bufnr) nnoremap("K", vim.lsp.buf.hover) nnoremap("rn", vim.lsp.buf.rename) nnoremap("ca", vim.lsp.buf.code_action) - nnoremap("f", vim.lsp.buf.format) + nnoremap("f", format_buffer) nnoremap("d", telescope.diagnostics) nnoremap("D", require("lsp_lines").toggle) nnoremap("", vim.diagnostic.goto_prev) nnoremap("", vim.diagnostic.goto_next) - -- disable tsserver formatting - if client.name == "tsserver" then - client.server_capabilities.document_formatting = false - end - if 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({ timeout_ms = 3000, async = false }) - end, + callback = format_buffer, }) end