nix-config/home/features/coding/nvim/plugin/none-ls.lua

48 lines
1.1 KiB
Lua
Raw Normal View History

2023-12-28 18:15:39 +01:00
local null_ls = require("null-ls")
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local opts = {
sources = {
-- Lua
null_ls.builtins.formatting.stylua,
-- Python
null_ls.builtins.formatting.black,
-- null_ls.builtins.diagnostics.ruff,
2023-12-28 18:15:39 +01:00
-- Javascript
-- null_ls.builtins.diagnostics.eslint_d,
-- null_ls.builtins.diagnostics.jsonlint,
2023-12-28 18:15:39 +01:00
-- C/C++
null_ls.builtins.formatting.clang_format,
-- Nix
null_ls.builtins.formatting.alejandra,
2024-02-16 12:19:41 +01:00
-- Rust
-- null_ls.builtins.formatting.rustfmt,
2024-03-03 13:08:33 +01:00
-- YAML
null_ls.builtins.formatting.yamlfmt,
2024-05-24 13:58:42 +02:00
-- Typescript
null_ls.builtins.formatting.prettier.with({
condition = function(utils)
return utils.has_file({ ".prettierrc.js" })
end,
}),
2023-12-28 18:15:39 +01:00
},
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 })
end,
})
end
end,
}
null_ls.setup(opts)
vim.keymap.set("n", "<leader>gf", vim.lsp.buf.format, {})