mirror of
https://github.com/arkorty/Neolite.git
synced 2026-03-18 09:02:29 +00:00
34 lines
883 B
Lua
34 lines
883 B
Lua
local ok, null_ls = pcall(require, "null-ls")
|
|
if not ok then
|
|
return
|
|
end
|
|
|
|
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
|
require("null-ls").setup({
|
|
sources = {
|
|
null_ls.builtins.formatting.rustfmt,
|
|
null_ls.builtins.formatting.stylua,
|
|
null_ls.builtins.formatting.black,
|
|
null_ls.builtins.formatting.prettier,
|
|
null_ls.builtins.formatting.clang_format,
|
|
},
|
|
-- 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()
|
|
vim.lsp.buf.format({
|
|
bufnr = bufnr,
|
|
filter = function()
|
|
return client.name == "null-ls"
|
|
end,
|
|
})
|
|
end,
|
|
})
|
|
end
|
|
end,
|
|
})
|