Initial commit

This commit is contained in:
Arkaprabha Chakraborty
2023-03-05 06:47:18 +05:30
commit 38e29f01ec
18 changed files with 721 additions and 0 deletions

29
lua/lsp-format.lua Normal file
View File

@@ -0,0 +1,29 @@
local ok, null_ls = pcall(require, "null-ls")
if not ok then
return
end
local formatting = null_ls.builtins.formatting
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
null_ls.setup({
sources = {
formatting.rustfmt,
formatting.stylua,
formatting.black,
formatting.prettier,
}, -- you can reuse a shared lspconfig on_attach callback here
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
-- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead
vim.lsp.buf.format({ bufnr = bufnr })
end,
})
end
end,
})