Add nvim lsp formatting configuration example
This commit is contained in:
parent
5e0ff0dbc5
commit
ca9edc9d38
2 changed files with 34 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
|||
-- example of a project specific nvim configuration file using :exrc
|
||||
-- example of a project specific nvim configuration file using :exrc and conform
|
||||
|
||||
local conform = require 'conform';
|
||||
|
||||
33
files/nvim.lsp.lua
Normal file
33
files/nvim.lsp.lua
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
-- example of a project specific nvim configuration file using :exrc and lsp formatting
|
||||
|
||||
local format_clients = {
|
||||
'ruff',
|
||||
'lua_ls',
|
||||
'bashls',
|
||||
'jsonls',
|
||||
'ts_ls',
|
||||
'ansiblels',
|
||||
'yamlls',
|
||||
'cssls',
|
||||
'html',
|
||||
}
|
||||
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
group = vim.api.nvim_create_augroup('lsp', { clear = true }),
|
||||
callback = function(args)
|
||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||
|
||||
if client:supports_method('textDocument/formatting')
|
||||
and vim.tbl_contains(format_clients, client.name) then
|
||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||
buffer = args.buf,
|
||||
callback = function()
|
||||
vim.lsp.buf.format {
|
||||
async = false,
|
||||
id = args.data.client_id
|
||||
}
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue