From c82793b1c7bceea0753ba29646d7df9066d0b9ea Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Sun, 12 Nov 2023 15:49:02 +1030 Subject: [PATCH] Remove null ls and replace with confirm.nvim and nvim-lint --- .config/nvim/lazy-lock.json | 5 +- .config/nvim/lua/tovi/plugins/formatting.lua | 44 +++++++++++++++ .config/nvim/lua/tovi/plugins/linting.lua | 38 +++++++++++++ .config/nvim/lua/tovi/plugins/lsp/mason.lua | 30 +++++----- .config/nvim/lua/tovi/plugins/lsp/null-ls.lua | 56 ------------------- 5 files changed, 101 insertions(+), 72 deletions(-) create mode 100644 .config/nvim/lua/tovi/plugins/formatting.lua create mode 100644 .config/nvim/lua/tovi/plugins/linting.lua delete mode 100644 .config/nvim/lua/tovi/plugins/lsp/null-ls.lua diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index afa0753..27db2cc 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -6,6 +6,7 @@ "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "conform.nvim": { "branch": "master", "commit": "ca3dfba94600aa62bfc88ae37cbd4f17eaea2553" }, "copilot.vim": { "branch": "release", "commit": "309b3c803d1862d5e84c7c9c5749ae04010123b8" }, "dart-vim-plugin": { "branch": "master", "commit": "928302ec931caf0dcf21835cca284ccd2b192f7b" }, "dressing.nvim": { "branch": "master", "commit": "fe3071330a0720ce3695ac915820c8134b22d1b0" }, @@ -21,16 +22,16 @@ "lspkind.nvim": { "branch": "master", "commit": "57610d5ab560c073c465d6faf0c19f200cb67e6e" }, "lualine.nvim": { "branch": "master", "commit": "2248ef254d0a1488a72041cfb45ca9caada6d994" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "6eb8cae80f2e4322ec82cd9f8fa423f6d1eb02c3" }, - "mason-null-ls.nvim": { "branch": "main", "commit": "ae0c5fa57468ac65617f1bf821ba0c3a1e251f0c" }, + "mason-tool-installer.nvim": { "branch": "main", "commit": "e4f34741daa9cf95de68a603d3e7a6844a69fdf0" }, "mason.nvim": { "branch": "main", "commit": "41e75af1f578e55ba050c863587cffde3556ffa6" }, "minintro.nvim": { "branch": "master", "commit": "6bbb922a5628f5bc746fa2e13dbf5f9b6049c6b1" }, "neotest": { "branch": "master", "commit": "901891484db3d46ce43d56871273dc7d40621356" }, "neotest-go": { "branch": "main", "commit": "1a15e1136db43775214a3e7a598f8930c29c94b7" }, "neotest-phpunit": { "branch": "main", "commit": "e2dfa3280d2a33495a3f710bc364d2cfd1f40c83" }, "nightfly": { "branch": "master", "commit": "06ad2689ebd251a71c6caeb9fb47e231773c9b47" }, - "null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" }, "nvim-cmp": { "branch": "main", "commit": "0b751f6beef40fd47375eaf53d3057e0bfa317e4" }, "nvim-colorizer.lua": { "branch": "master", "commit": "dde3084106a70b9a79d48f426f6d6fec6fd203f7" }, + "nvim-lint": { "branch": "master", "commit": "775ae0e5a451dd6c5d15de7a828ea72d2c54e8cf" }, "nvim-lsp-file-operations": { "branch": "master", "commit": "1e0ffa0acc92f88f9f2b68df47ccbe1917653a42" }, "nvim-lspconfig": { "branch": "master", "commit": "90a28fd7637b66e055af62387ecee06f7cbd3173" }, "nvim-tree.lua": { "branch": "master", "commit": "874ae6e9445a5eb5ba430e5fd10212450a261ad7" }, diff --git a/.config/nvim/lua/tovi/plugins/formatting.lua b/.config/nvim/lua/tovi/plugins/formatting.lua new file mode 100644 index 0000000..0d14e9b --- /dev/null +++ b/.config/nvim/lua/tovi/plugins/formatting.lua @@ -0,0 +1,44 @@ +return { + "stevearc/conform.nvim", + event = { "BufReadPre", "BufNewFile" }, + config = function() + local conform = require("conform") + + conform.setup({ + formatters_by_ft = { + lua = { "stylua" }, + go = { "goimports", "gofmt" }, + javascript = { "prettier" }, + typescript = { "prettier" }, + vue = { "prettier" }, + css = { "prettier" }, + html = { "prettier" }, + markdown = { "prettier" }, + json = { "fixjson" }, + rust = { "rustfmt" }, + shell = { "shfmt", "shellcheck" }, + python = { "isort", "black" }, + ["*"] = { "codespell" }, + ["_"] = { "trim_whitespace" }, + }, + format_on_save = { + lsp_fallback = true, + async = false, + timeout_ms = 500, + }, + format_after_save = { + lsp_fallback = true, + }, + log_level = vim.log.levels.ERROR, + notify_on_error = true, + }) + + vim.keymap.set({ "n", "v" }, "ff", function() + conform.format({ + lsp_fallback = true, + async = false, + timeout_ms = 500, + }) + end) + end, +} diff --git a/.config/nvim/lua/tovi/plugins/linting.lua b/.config/nvim/lua/tovi/plugins/linting.lua new file mode 100644 index 0000000..0d3842a --- /dev/null +++ b/.config/nvim/lua/tovi/plugins/linting.lua @@ -0,0 +1,38 @@ +return { + "mfussenegger/nvim-lint", + event = { "BufReadPre", "BufNewFile" }, + config = function() + local lint = require("lint") + + lint.linters_by_ft = { + javascript = { "eslint_d" }, + typescript = { "eslint_d" }, + vue = { "eslint_d" }, + json = { "jsonlint" }, + markdown = { "markdownlint" }, + php = { "phpcs" }, + golang = { "gospell", "golangci-lint" }, + python = { "pylint" }, + dockerfile = { "hadolint" }, + } + + local lint_augroup = vim.api.nvim_create_augroup("lint", { + clear = true, + }) + + vim.api.nvim_create_autocmd({ + "BufEnter", + "BufWritePost", + "InsertLeave", + }, { + group = lint_augroup, + callback = function() + lint.try_lint() + end, + }) + + vim.keymap.set("n", "ll", function() + lint.try_lint() + end) + end, +} diff --git a/.config/nvim/lua/tovi/plugins/lsp/mason.lua b/.config/nvim/lua/tovi/plugins/lsp/mason.lua index 38488ff..cf10105 100644 --- a/.config/nvim/lua/tovi/plugins/lsp/mason.lua +++ b/.config/nvim/lua/tovi/plugins/lsp/mason.lua @@ -2,7 +2,7 @@ return { "williamboman/mason.nvim", dependencies = { "williamboman/mason-lspconfig.nvim", - "jayp0521/mason-null-ls.nvim", + "WhoIsSethDaniel/mason-tool-installer.nvim", }, config = function() -- import mason @@ -11,8 +11,7 @@ return { -- import mason-lspconfig local mason_lspconfig = require("mason-lspconfig") - -- import mason-null-ls - local mason_null_ls = require("mason-null-ls") + local mason_tool_installer = require("mason-tool-installer") -- enable mason and configure icons mason.setup({ @@ -34,25 +33,28 @@ return { "tailwindcss", "svelte", "lua_ls", - "graphql", "emmet_ls", - "prismals", "pyright", "intelephense", - "gopls", + "gopls", }, - -- auto-install configured servers (with lspconfig) - automatic_installation = true, -- not the same as ensure_installed + automatic_installation = true, }) - mason_null_ls.setup({ - -- list of formatters & linters for mason to install + mason_tool_installer.setup({ ensure_installed = { - "prettier", -- ts/js formatter - "stylua", -- lua formatter - "eslint_d", -- ts/js linter + "prettier", + "eslint_d", + "jsonlint", + "markdownlint", + "phpcs", + "gospel", + "golangci-lint", + "pylint", + "hadolint", + "gofumpt", + "goimports", }, - -- auto-install configured servers (with lspconfig) automatic_installation = true, }) end, diff --git a/.config/nvim/lua/tovi/plugins/lsp/null-ls.lua b/.config/nvim/lua/tovi/plugins/lsp/null-ls.lua deleted file mode 100644 index a3b32fd..0000000 --- a/.config/nvim/lua/tovi/plugins/lsp/null-ls.lua +++ /dev/null @@ -1,56 +0,0 @@ -return { - "jose-elias-alvarez/null-ls.nvim", -- configure formatters & linters - event = { "BufReadPre", "BufNewFile" }, - config = function() - -- import null-ls plugin - local null_ls = require("null-ls") - - local null_ls_utils = require("null-ls.utils") - - -- for conciseness - local formatting = null_ls.builtins.formatting -- to setup formatters - local diagnostics = null_ls.builtins.diagnostics -- to setup linters - - -- to setup format on save - local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) - - -- configure null_ls - null_ls.setup({ - -- add package.json as identifier for root (for typescript monorepos) - root_dir = null_ls_utils.root_pattern(".null-ls-root", "Makefile", ".git", "package.json"), - -- setup formatters & linters - sources = { - -- to disable file types use - -- "formatting.prettier.with({disabled_filetypes: {}})" (see null-ls docs) - formatting.prettier.with({ - extra_filetypes = { "svelte" }, - }), -- js/ts formatter - formatting.stylua, -- lua formatter - diagnostics.eslint_d.with({ -- js/ts linter - condition = function(utils) - return utils.root_has_file({ ".eslintrc.js", ".eslintrc.cjs" }) -- only enable if root has .eslintrc.js or .eslintrc.cjs - end, - }), - }, - -- configure format on save - -- on_attach = function(current_client, bufnr) - -- if current_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({ - -- filter = function(client) - -- -- only use null-ls for formatting instead of lsp server - -- return client.name == "null-ls" - -- end, - -- bufnr = bufnr, - -- }) - -- end, - -- }) - -- end - -- end, - }) - end, -}