From b1e951ef1df095668d74c4bfe8d29ce43ed5f2b6 Mon Sep 17 00:00:00 2001 From: Alexander Gehrke Date: Thu, 4 Apr 2024 18:18:22 +0200 Subject: [PATCH] Use conform.nvim for fold-preserving formatting --- after/ftplugin/scala.vim | 4 ++++ lazy-lock.json | 2 +- lua/plugins/conform.lua | 37 +++++++++++++++++++++++++++++++++++++ lua/plugins/exttools.lua | 8 -------- plugin/on-attach.lua | 18 ++++++++++-------- 5 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 lua/plugins/conform.lua diff --git a/after/ftplugin/scala.vim b/after/ftplugin/scala.vim index 60759ed..ba52db4 100644 --- a/after/ftplugin/scala.vim +++ b/after/ftplugin/scala.vim @@ -3,3 +3,7 @@ map cl :call jobstart(['codelines', '.']) set tw=120 set foldlevel=99 + +set foldmethod=indent +"set foldmethod=expr +"set foldexpr=nvim_treesitter#foldexpr() diff --git a/lazy-lock.json b/lazy-lock.json index 49f3d29..1e2486c 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -7,11 +7,11 @@ "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "conform.nvim": { "branch": "master", "commit": "9d5ba06d6ee7418c674f498634617416d15b6239" }, "copilot-cmp": { "branch": "master", "commit": "72fbaa03695779f8349be3ac54fa8bd77eed3ee3" }, "copilot.lua": { "branch": "master", "commit": "f7612f5af4a7d7615babf43ab1e67a2d790c13a6" }, "deepl.vim": { "branch": "main", "commit": "59df8cc17bb28989ce562bf4712c724d23baadcd" }, "dressing.nvim": { "branch": "master", "commit": "18e5beb3845f085b6a33c24112b37988f3f93c06" }, - "formatter.nvim": { "branch": "master", "commit": "ad246d34ce7a32f752071ed81b09b94e6b127fad" }, "gen.nvim": { "branch": "main", "commit": "46ab810130097494bbcf12b1426a7166f4c2995e" }, "gina.vim": { "branch": "master", "commit": "ff6c2ddeca98f886b57fb42283c12e167d6ab575" }, "gitsigns.nvim": { "branch": "main", "commit": "078041e9d060a386b0c9d3a8c7a7b019a35d3fb0" }, diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua new file mode 100644 index 0000000..e1683db --- /dev/null +++ b/lua/plugins/conform.lua @@ -0,0 +1,37 @@ +return { + "stevearc/conform.nvim", + event = { "BufWritePre" }, + cmd = { "ConformInfo" }, + keys = { + { + -- Customize or remove this keymap to your liking + "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, +} diff --git a/lua/plugins/exttools.lua b/lua/plugins/exttools.lua index f288631..583154d 100644 --- a/lua/plugins/exttools.lua +++ b/lua/plugins/exttools.lua @@ -1,11 +1,3 @@ return { 'mfussenegger/nvim-lint', - { - 'mhartington/formatter.nvim', - opts = function() - return { - - } - end - } } diff --git a/plugin/on-attach.lua b/plugin/on-attach.lua index 21b018c..1e45654 100644 --- a/plugin/on-attach.lua +++ b/plugin/on-attach.lua @@ -10,7 +10,7 @@ local on_attach = function(args) -- -- Mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions + -- stylua: ignore start for _, mapping in ipairs({ { 'gD', vim.lsp.buf.declaration, "Go to declaration" }, { 'gd', require('telescope.builtin').lsp_definitions, "Go to definition" }, @@ -25,29 +25,31 @@ local on_attach = function(args) { '[d', vim.diagnostic.goto_prev, "Go to previous diagnostic" }, { '[d', vim.diagnostic.goto_prev, "Go to next diagnostic" }, { '', vim.diagnostic.setloclist, "Add buffer diagnostics to location list" }, - { "f", function() vim.lsp.buf.format { async = true } end, "Format buffer" }, { "dc", function() require("dap").continue() end, "Debug: Continue" }, { "dK", function() require("dap.ui.widgets").hover() end, "Debug: Hover" }, { "dt", function() require("dap").toggle_breakpoint() end, "Debug: Toggle breakpoint" }, { "dso", function() require("dap").step_over() end, "Debug: Step over" }, { "dsi", function() require("dap").step_into() end, "Debug: Step into" }, { "dl", function() require("dap").run_last() end, "Debug: Run last" }, - { "", function() require("dap").continue() end, "Debug: Continue" }, - { "", function() require("dap.ui.widgets").hover() end, "Debug: Hover" }, + { "", function() require("dap").continue() end, "Debug: Continue" }, + { "", function() require("dap.ui.widgets").hover() end, "Debug: Hover" }, { "", function() require("dap").step_over() end, "Debug: Step over" }, { "", function() require("dap").step_into() end, "Debug: Step into" }, { "aa", vim.diagnostic.setqflist, "Add all diagnostics to quickfix list" }, { "aw", function() vim.diagnostic.setqflist({ severity = "W" }) end, "Add all warnings to quickfix list" }, { "ae", function() vim.diagnostic.setqflist({ severity = "E" }) end, "Add all errors to quickfix list" }, }) 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 + -- stylua: ignore end - vim.keymap.set("n", "dr", function() require("dap").repl.toggle() end, { silent = true, desc = "Toogle debug REPL" }) + vim.keymap.set("n", "dr", function() + require("dap").repl.toggle() + end, { silent = true, desc = "Toogle debug REPL" }) if client.server_capabilities.signatureHelpProvider then - 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 CursorHoldI * silent! lua vim.lsp.buf.signature_help()]]) + vim.cmd([[autocmd CursorHold * lua vim.diagnostic.open_float({max_width = 100, focusable = false})]]) end if client.server_capabilities.documentHighlightingProvider then