From 44dae3a940e0de7e8d7a5f610e7e6c6fc8d86042 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 1 Mar 2022 15:09:24 +0100 Subject: [PATCH] home: vim: move LSP-related 'on_attach' to 'utils' As it will be shared between `null-ls` and `lspconfig`, it makes sense to put it there. --- home/vim/lua/ambroisie/utils.lua | 15 +++++++++++++++ home/vim/plugin/settings/null-ls.vim | 12 +----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/home/vim/lua/ambroisie/utils.lua b/home/vim/lua/ambroisie/utils.lua index 8a6cb0f..2b502a4 100644 --- a/home/vim/lua/ambroisie/utils.lua +++ b/home/vim/lua/ambroisie/utils.lua @@ -14,4 +14,19 @@ M.is_executable_condition = function(cmd) return function() return M.is_executable(cmd) end end +-- shared LSP configuration callback +-- @param client native client configuration +-- @param bufnr int? buffer number of the attched client +M.on_attach = function(client, bufnr) + -- Format on save + if client.resolved_capabilities.document_formatting then + vim.cmd([[ + augroup LspFormatting + autocmd! * + autocmd BufWritePre lua vim.lsp.buf.formatting_sync() + augroup END + ]]) + end +end + return M diff --git a/home/vim/plugin/settings/null-ls.vim b/home/vim/plugin/settings/null-ls.vim index a3972a2..c241935 100644 --- a/home/vim/plugin/settings/null-ls.vim +++ b/home/vim/plugin/settings/null-ls.vim @@ -3,17 +3,7 @@ local null_ls = require("null-ls") local utils = require("ambroisie.utils") null_ls.setup({ - on_attach = function(client) - -- Format on save - if client.resolved_capabilities.document_formatting then - vim.cmd([[ - augroup LspFormatting - autocmd! * - autocmd BufWritePre lua vim.lsp.buf.formatting_sync() - augroup END - ]]) - end - end, + on_attach = utils.on_attach, }) -- C, C++