home: vim: lua: lsp: update for nvim 0.8

Two big changes:

* Making use of the lua API for creating autocmds.
* Using `client.supports_method`.
This commit is contained in:
Bruno BELANYI 2022-11-03 17:57:41 +01:00
parent f6a00ec838
commit 236d48befb

View file

@ -18,22 +18,28 @@ M.on_attach = function(client, bufnr)
severity_sort = true,
})
vim.cmd([[
augroup DiagnosticsHover
autocmd! * <buffer>
" Show diagnostics on "hover"
autocmd CursorHold,CursorHoldI <buffer> lua vim.diagnostic.open_float(nil, {focus=false, scope="cursor"})
augroup END
]])
-- Show diagnostics on "hover"
local augroup = vim.api.nvim_create_augroup("DiagnosticsHover", {})
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI"}, {
group = augroup,
buffer = bufnr,
callback = function()
vim.diagnostic.open_float(nil, {focus=false, scope="cursor"})
end,
})
-- 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
]])
if client.supports_method("textDocument/formatting") then
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
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 })
end,
})
end
-- Mappings