|
@@ -97,8 +97,29 @@ if vim.fn.executable("nil") == 1 then
|
|
});
|
|
});
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+-- format on save
|
|
local group = vim.api.nvim_create_augroup('LspFormatting', { clear = false })
|
|
local group = vim.api.nvim_create_augroup('LspFormatting', { clear = false })
|
|
|
|
|
|
|
|
+vim.api.nvim_create_autocmd('LspAttach', {
|
|
|
|
+ callback = function(args)
|
|
|
|
+ local bufnr = args.buf
|
|
|
|
+ local client = vim.lsp.get_client_by_id(args.data.client_id)
|
|
|
|
+
|
|
|
|
+ if client.server_capabilities.documentFormattingProvider then
|
|
|
|
+ for key, cmd in pairs(vim.api.nvim_get_autocmds({ group = group, buffer = bufnr })) do
|
|
|
|
+ vim.api.nvim_del_autocmd(cmd.id)
|
|
|
|
+ end
|
|
|
|
+ vim.api.nvim_create_autocmd('BufWritePre', {
|
|
|
|
+ group = group,
|
|
|
|
+ buffer = bufnr,
|
|
|
|
+ callback = function()
|
|
|
|
+ vim.lsp.buf.format()
|
|
|
|
+ end,
|
|
|
|
+ })
|
|
|
|
+ end
|
|
|
|
+ end,
|
|
|
|
+})
|
|
|
|
+
|
|
-- custom LSP servers
|
|
-- custom LSP servers
|
|
local configs = require('lspconfig.configs')
|
|
local configs = require('lspconfig.configs')
|
|
|
|
|