From 9421365706a5cd01c037957c86bc4304e8ba3250 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Wed, 20 Mar 2024 08:51:43 -0500 Subject: [PATCH] refactor(nvim): replace `formatter` & `nvim-lint` with `none-ls` --- .../nvim/lua/plugins/configs/formatter.lua | 79 ------------------- dots/.config/nvim/lua/plugins/configs/lsp.lua | 32 ++++++++ .../nvim/lua/plugins/configs/nvim-lint.lua | 17 ---- 3 files changed, 32 insertions(+), 96 deletions(-) delete mode 100644 dots/.config/nvim/lua/plugins/configs/formatter.lua delete mode 100644 dots/.config/nvim/lua/plugins/configs/nvim-lint.lua diff --git a/dots/.config/nvim/lua/plugins/configs/formatter.lua b/dots/.config/nvim/lua/plugins/configs/formatter.lua deleted file mode 100644 index 07703113..00000000 --- a/dots/.config/nvim/lua/plugins/configs/formatter.lua +++ /dev/null @@ -1,79 +0,0 @@ -return { - { - "mhartington/formatter.nvim", - keys = { - { - "lf", - function() - local active_clients = vim.iter( - vim.lsp.get_clients({ bufnr = 0, method = "textDocument/formatting" }) - ) - :filter(function(lsp_client) - -- Exclude some language server formatters. - -- - -- I chose not to override the `textDocument/formatting` handler because - -- it felt kinda hacky and some language servers don't play nice with - -- changing their handlers. Figured this was easier. - if lsp_client.config and lsp_client.config.name then - return not vim.list_contains({ - "lua_ls", - }, lsp_client.config.name) - end - return true - end) - 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", - mode = { "v", "n" }, - }, - }, - opts = function() - local filetypes = require("formatter.filetypes") - return { - logging = true, - log_level = vim.log.levels.WARN, - filetype = { - markdown = filetypes.markdown.prettierd, - css = filetypes.css.prettierd, - lua = filetypes.lua.stylua, - sql = function() - return { - exe = "sql-formatter", - args = { - "-l", - "postgresql", - "--fix", - }, - } - end, - zsh = function() - return { - exe = "shfmt", - args = { - "-", - }, - stdin = true, - } - end, - asm = function() - return { - exe = "asmfmt", - stdin = true, - } - end, - typst = function() - return { - exe = "typstfmt", - stdin = true, - } - end, - }, - } - end, - }, -} diff --git a/dots/.config/nvim/lua/plugins/configs/lsp.lua b/dots/.config/nvim/lua/plugins/configs/lsp.lua index 4632dc8c..dd0bd10e 100644 --- a/dots/.config/nvim/lua/plugins/configs/lsp.lua +++ b/dots/.config/nvim/lua/plugins/configs/lsp.lua @@ -192,9 +192,41 @@ return { event = { "BufReadPre", "BufNewFile" }, config = true, }, + { + "nvimtools/none-ls.nvim", + config = function() + local null_ls = require("null-ls") + null_ls.setup({ + sources = { + null_ls.builtins.formatting.stylua, + null_ls.builtins.formatting.asmfmt, + null_ls.builtins.formatting.black, + null_ls.builtins.formatting.typstfmt, + null_ls.builtins.formatting.cmake_format, + null_ls.builtins.formatting.shfmt, + null_ls.builtins.formatting.shellharden, + null_ls.builtins.formatting.prettierd, + null_ls.builtins.diagnostics.hadolint, + }, + }) + end, + }, }, keys = { { "l", desc = "> LSP" }, + { + "lf", + function() + vim.lsp.buf.format({ + async = true, + filter = function(client) + return not vim.list_contains({ "lua_ls" }, client.name) + end, + }) + end, + desc = "LSP: Format", + mode = { "v", "n" }, + }, { "lh", function() diff --git a/dots/.config/nvim/lua/plugins/configs/nvim-lint.lua b/dots/.config/nvim/lua/plugins/configs/nvim-lint.lua deleted file mode 100644 index 12a4d01b..00000000 --- a/dots/.config/nvim/lua/plugins/configs/nvim-lint.lua +++ /dev/null @@ -1,17 +0,0 @@ -return { - { - "mfussenegger/nvim-lint", - event = { "BufReadPre", "BufNewFile" }, - config = function() - require("lint").linters_by_ft = { - markdown = { "proselint" }, - dockerfile = { "hadolint" }, - } - vim.api.nvim_create_autocmd({ "BufWritePost", "BufEnter" }, { - callback = function() - require("lint").try_lint() - end, - }) - end, - }, -}