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.
This commit is contained in:
Bruno BELANYI 2022-03-01 15:09:24 +01:00
parent b79cee6eee
commit 44dae3a940
2 changed files with 16 additions and 11 deletions

View file

@ -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! * <buffer>
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()
augroup END
]])
end
end
return M

View file

@ -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! * <buffer>
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()
augroup END
]])
end
end,
on_attach = utils.on_attach,
})
-- C, C++