From 7932fb1d55f2c560c60247d1d2d9b22465f7ddd1 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 9 Jan 2022 00:22:22 +0000 Subject: [PATCH] fix(nvim): format files on save with `null-ls` --- roles/neovim/files/lua/opdavies/lsp/init.lua | 2 ++ roles/neovim/files/lua/opdavies/lsp/null-ls.lua | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/roles/neovim/files/lua/opdavies/lsp/init.lua b/roles/neovim/files/lua/opdavies/lsp/init.lua index 5c5d9ff..f00e546 100644 --- a/roles/neovim/files/lua/opdavies/lsp/init.lua +++ b/roles/neovim/files/lua/opdavies/lsp/init.lua @@ -36,3 +36,5 @@ lspconfig.tailwindcss.setup { } require("opdavies.lsp.handlers").setup() + +require "opdavies.lsp.null-ls" diff --git a/roles/neovim/files/lua/opdavies/lsp/null-ls.lua b/roles/neovim/files/lua/opdavies/lsp/null-ls.lua index b6b5e7d..6227cb1 100644 --- a/roles/neovim/files/lua/opdavies/lsp/null-ls.lua +++ b/roles/neovim/files/lua/opdavies/lsp/null-ls.lua @@ -14,4 +14,15 @@ null_ls.setup { diagnostics.eslint, completion.spell, }, + + on_attach = function(client) + if client.resolved_capabilities.document_formatting then + vim.cmd [[ + augroup LspFormatting + autocmd! * + autocmd BufWritePre lua vim.lsp.buf.formatting_sync() + augroup END + ]] + end + end, }