mirror of
https://github.com/mikkelsvartveit/dotfiles.git
synced 2025-12-22 11:12:39 +00:00
Set up format on save
This commit is contained in:
parent
b673b2e389
commit
a8057cb6a9
2 changed files with 35 additions and 0 deletions
|
|
@ -10,6 +10,7 @@
|
|||
"mason-lspconfig.nvim": { "branch": "main", "commit": "67da97f8c2fd12d05427bb485ce07ee6418e0a51" },
|
||||
"mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" },
|
||||
"neoscroll.nvim": { "branch": "master", "commit": "f957373912e88579e26fdaea4735450ff2ef5c9c" },
|
||||
"none-ls.nvim": { "branch": "main", "commit": "db2a48b79cfcdab8baa5d3f37f21c78b6705c62e" },
|
||||
"nvim-autopairs": { "branch": "master", "commit": "4d74e75913832866aa7de35e4202463ddf6efd1b" },
|
||||
"nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "b8e7957bde4cbb3cb25a13a62548f7c273b026e9" },
|
||||
|
|
|
|||
|
|
@ -96,6 +96,40 @@ require("lazy").setup({
|
|||
end,
|
||||
},
|
||||
|
||||
-- Formatting with null-ls
|
||||
{
|
||||
"nvimtools/none-ls.nvim",
|
||||
dependencies = { "nvim-lua/plenary.nvim" },
|
||||
config = function()
|
||||
local null_ls = require("null-ls")
|
||||
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
||||
null_ls.setup({
|
||||
sources = {
|
||||
null_ls.builtins.formatting.prettierd,
|
||||
null_ls.builtins.formatting.black,
|
||||
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()
|
||||
vim.lsp.buf.format({
|
||||
async = false,
|
||||
filter = function(client)
|
||||
return client.name == "null-ls"
|
||||
end
|
||||
})
|
||||
end,
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
end,
|
||||
},
|
||||
|
||||
-- Easy commenting/uncommenting
|
||||
{
|
||||
"numToStr/Comment.nvim",
|
||||
|
|
|
|||
Loading…
Reference in a new issue