add: setup file for null-ls
This commit is contained in:
parent
76152e4132
commit
6c23ba8ea3
1 changed files with 42 additions and 0 deletions
42
.config/nvim/after/plugin/null-ls.rc.lua
Normal file
42
.config/nvim/after/plugin/null-ls.rc.lua
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
local status, null_ls = pcall(require, "null-ls")
|
||||||
|
if not status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
||||||
|
|
||||||
|
local lsp_formatting = function(bufnr)
|
||||||
|
vim.lsp.buf.format({
|
||||||
|
filter = function(client)
|
||||||
|
return client.name == "null-ls"
|
||||||
|
end,
|
||||||
|
bufnr = bufnr,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
null_ls.setup({
|
||||||
|
sources = {
|
||||||
|
null_ls.builtins.formatting.prettierd,
|
||||||
|
null_ls.builtins.formatting.autopep8,
|
||||||
|
null_ls.builtins.formatting.stylua,
|
||||||
|
},
|
||||||
|
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()
|
||||||
|
lsp_formatting(bufnr)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_user_command("DisableLspFormatting", function()
|
||||||
|
vim.api.nvim_clear_autocmds({ group = augroup, buffer = 0 })
|
||||||
|
end, { nargs = 0 })
|
||||||
Loading…
Add table
Add a link
Reference in a new issue