Use conform.nvim for fold-preserving formatting

This commit is contained in:
Alexander Gehrke 2024-04-04 18:18:22 +02:00
parent 855db2feee
commit b1e951ef1d
5 changed files with 52 additions and 17 deletions

View file

@ -3,3 +3,7 @@ map <silent> <buffer> <leader>cl :call jobstart(['codelines', '.'])<cr>
set tw=120 set tw=120
set foldlevel=99 set foldlevel=99
set foldmethod=indent
"set foldmethod=expr
"set foldexpr=nvim_treesitter#foldexpr()

View file

@ -7,11 +7,11 @@
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"conform.nvim": { "branch": "master", "commit": "9d5ba06d6ee7418c674f498634617416d15b6239" },
"copilot-cmp": { "branch": "master", "commit": "72fbaa03695779f8349be3ac54fa8bd77eed3ee3" }, "copilot-cmp": { "branch": "master", "commit": "72fbaa03695779f8349be3ac54fa8bd77eed3ee3" },
"copilot.lua": { "branch": "master", "commit": "f7612f5af4a7d7615babf43ab1e67a2d790c13a6" }, "copilot.lua": { "branch": "master", "commit": "f7612f5af4a7d7615babf43ab1e67a2d790c13a6" },
"deepl.vim": { "branch": "main", "commit": "59df8cc17bb28989ce562bf4712c724d23baadcd" }, "deepl.vim": { "branch": "main", "commit": "59df8cc17bb28989ce562bf4712c724d23baadcd" },
"dressing.nvim": { "branch": "master", "commit": "18e5beb3845f085b6a33c24112b37988f3f93c06" }, "dressing.nvim": { "branch": "master", "commit": "18e5beb3845f085b6a33c24112b37988f3f93c06" },
"formatter.nvim": { "branch": "master", "commit": "ad246d34ce7a32f752071ed81b09b94e6b127fad" },
"gen.nvim": { "branch": "main", "commit": "46ab810130097494bbcf12b1426a7166f4c2995e" }, "gen.nvim": { "branch": "main", "commit": "46ab810130097494bbcf12b1426a7166f4c2995e" },
"gina.vim": { "branch": "master", "commit": "ff6c2ddeca98f886b57fb42283c12e167d6ab575" }, "gina.vim": { "branch": "master", "commit": "ff6c2ddeca98f886b57fb42283c12e167d6ab575" },
"gitsigns.nvim": { "branch": "main", "commit": "078041e9d060a386b0c9d3a8c7a7b019a35d3fb0" }, "gitsigns.nvim": { "branch": "main", "commit": "078041e9d060a386b0c9d3a8c7a7b019a35d3fb0" },

37
lua/plugins/conform.lua Normal file
View file

@ -0,0 +1,37 @@
return {
"stevearc/conform.nvim",
event = { "BufWritePre" },
cmd = { "ConformInfo" },
keys = {
{
-- Customize or remove this keymap to your liking
"<leader>f",
function()
require("conform").format({ async = true, lsp_fallback = true })
end,
mode = "",
desc = "Format buffer",
},
},
-- Everything in opts will be passed to setup()
opts = {
-- Define your formatters
formatters_by_ft = {
lua = { "stylua" },
python = { "isort", "black" },
javascript = { { "prettierd", "prettier" } },
},
-- Set up format-on-save
format_on_save = { timeout_ms = 500, lsp_fallback = true },
-- Customize formatters
formatters = {
shfmt = {
prepend_args = { "-i", "2" },
},
},
},
init = function()
-- If you want the formatexpr, here is the place to set it
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end,
}

View file

@ -1,11 +1,3 @@
return { return {
'mfussenegger/nvim-lint', 'mfussenegger/nvim-lint',
{
'mhartington/formatter.nvim',
opts = function()
return {
}
end
}
} }

View file

@ -10,7 +10,7 @@ local on_attach = function(args)
-- --
-- Mappings. -- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions -- stylua: ignore start
for _, mapping in ipairs({ for _, mapping in ipairs({
{ 'gD', vim.lsp.buf.declaration, "Go to declaration" }, { 'gD', vim.lsp.buf.declaration, "Go to declaration" },
{ 'gd', require('telescope.builtin').lsp_definitions, "Go to definition" }, { 'gd', require('telescope.builtin').lsp_definitions, "Go to definition" },
@ -25,7 +25,6 @@ local on_attach = function(args)
{ '[d', vim.diagnostic.goto_prev, "Go to previous diagnostic" }, { '[d', vim.diagnostic.goto_prev, "Go to previous diagnostic" },
{ '[d', vim.diagnostic.goto_prev, "Go to next diagnostic" }, { '[d', vim.diagnostic.goto_prev, "Go to next diagnostic" },
{ '<M-q>', vim.diagnostic.setloclist, "Add buffer diagnostics to location list" }, { '<M-q>', vim.diagnostic.setloclist, "Add buffer diagnostics to location list" },
{ "<Leader>f", function() vim.lsp.buf.format { async = true } end, "Format buffer" },
{ "<leader>dc", function() require("dap").continue() end, "Debug: Continue" }, { "<leader>dc", function() require("dap").continue() end, "Debug: Continue" },
{ "<leader>dK", function() require("dap.ui.widgets").hover() end, "Debug: Hover" }, { "<leader>dK", function() require("dap.ui.widgets").hover() end, "Debug: Hover" },
{ "<leader>dt", function() require("dap").toggle_breakpoint() end, "Debug: Toggle breakpoint" }, { "<leader>dt", function() require("dap").toggle_breakpoint() end, "Debug: Toggle breakpoint" },
@ -40,14 +39,17 @@ local on_attach = function(args)
{ "<leader>aw", function() vim.diagnostic.setqflist({ severity = "W" }) end, "Add all warnings to quickfix list" }, { "<leader>aw", function() vim.diagnostic.setqflist({ severity = "W" }) end, "Add all warnings to quickfix list" },
{ "<leader>ae", function() vim.diagnostic.setqflist({ severity = "E" }) end, "Add all errors to quickfix list" }, { "<leader>ae", function() vim.diagnostic.setqflist({ severity = "E" }) end, "Add all errors to quickfix list" },
}) do }) do
vim.keymap.set('n', mapping[1], mapping[2], { silent = true, buffer = args.buf, desc = mapping[3] }) vim.keymap.set("n", mapping[1], mapping[2], { silent = true, buffer = args.buf, desc = mapping[3] })
end end
-- stylua: ignore end
vim.keymap.set("n", "<leader>dr", function() require("dap").repl.toggle() end, { silent = true, desc = "Toogle debug REPL" }) vim.keymap.set("n", "<leader>dr", function()
require("dap").repl.toggle()
end, { silent = true, desc = "Toogle debug REPL" })
if client.server_capabilities.signatureHelpProvider then if client.server_capabilities.signatureHelpProvider then
vim.cmd [[autocmd CursorHoldI * silent! lua vim.lsp.buf.signature_help()]] vim.cmd([[autocmd CursorHoldI * silent! lua vim.lsp.buf.signature_help()]])
vim.cmd [[autocmd CursorHold * lua vim.diagnostic.open_float({max_width = 100, focusable = false})]] vim.cmd([[autocmd CursorHold * lua vim.diagnostic.open_float({max_width = 100, focusable = false})]])
end end
if client.server_capabilities.documentHighlightingProvider then if client.server_capabilities.documentHighlightingProvider then