From abb95f51b40c3c1bfffbff03af5961a81473939f Mon Sep 17 00:00:00 2001 From: Bryan Ramos Date: Tue, 29 Aug 2023 06:35:19 -0400 Subject: [PATCH] on_attach --- .../config/lazyvim/lua/config/autocmds.lua | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/homeConfig/modules/neovim/config/lazyvim/lua/config/autocmds.lua b/homeConfig/modules/neovim/config/lazyvim/lua/config/autocmds.lua index 28d086d..a56241a 100644 --- a/homeConfig/modules/neovim/config/lazyvim/lua/config/autocmds.lua +++ b/homeConfig/modules/neovim/config/lazyvim/lua/config/autocmds.lua @@ -22,26 +22,28 @@ require("notify").setup({ local lsp = require("lsp-zero").preset({}) local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) +local on_attach = function(client, bufnr) + 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({ + bufnr = bufnr, + filter = function(client) + return client.name == "null-ls" + end, + }) + vim.lsp.buf.formatting_sync() + end, + }) + end +end + require("null-ls").setup({ -- you can reuse a shared lspconfig on_attach callback here - on_attach = function(client, bufnr) - 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({ - bufnr = bufnr, - filter = function(client) - return client.name == "null-ls" - end, - }) - vim.lsp.buf.formatting_sync() - end, - }) - end - end, + on_attach = on_attach, }) -- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md