From 92b6ca2052821c55200bed0e3b9c495e5475268c Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Mon, 28 Aug 2023 15:58:41 -0500 Subject: [PATCH] feat(nvim): add formatter.nvim --- .../nvim/lua/plugins/configs/formatter.lua | 30 +++++++++++++++++++ dots/.config/nvim/lua/plugins/configs/lsp.lua | 7 ----- 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 dots/.config/nvim/lua/plugins/configs/formatter.lua diff --git a/dots/.config/nvim/lua/plugins/configs/formatter.lua b/dots/.config/nvim/lua/plugins/configs/formatter.lua new file mode 100644 index 00000000..fef0eeba --- /dev/null +++ b/dots/.config/nvim/lua/plugins/configs/formatter.lua @@ -0,0 +1,30 @@ +return { + { + "mhartington/formatter.nvim", + keys = { + { + "lf", + function() + local active_clients = vim.lsp.get_clients({ bufnr = 0, method = "textDocument/formatting" }) + if #active_clients > 0 then + vim.lsp.buf.format({ async = true }) + else + vim.cmd.Format() + end + end, + -- I know this is a lie below, but I'm used to the key being LSP bound, so fuck it + desc = "LSP: Format", + }, + }, + opts = function() + local filetypes = require("formatter.filetypes") + return { + logging = true, + log_level = vim.log.levels.WARN, + filetype = { + markdown = filetypes.markdown.prettierd, + }, + } + end, + }, +} diff --git a/dots/.config/nvim/lua/plugins/configs/lsp.lua b/dots/.config/nvim/lua/plugins/configs/lsp.lua index f8ab300b..1dbc3afd 100644 --- a/dots/.config/nvim/lua/plugins/configs/lsp.lua +++ b/dots/.config/nvim/lua/plugins/configs/lsp.lua @@ -125,13 +125,6 @@ return { end, desc = "LSP: Diagnostic Open Float", }, - { - "lf", - function() - vim.lsp.buf.format({ async = true }) - end, - desc = "LSP: Format", - }, { "[l", vim.diagnostic.goto_prev, desc = "LSP: Diagnostic Previous" }, { "]l", vim.diagnostic.goto_next, desc = "LSP: Diagnostic Next" }, {