From 5cbae7031efc119334406e6e2ed0dc94a02be57d Mon Sep 17 00:00:00 2001 From: daUnknownCoder Date: Fri, 1 Mar 2024 23:38:25 +0530 Subject: [PATCH] feat(no-null-ls)!: Remove null-ls, replace with conform and nvim-lint BREAKING CHANGE: conform.nvim and nvim-lint introduced again after v1.0.0 --- lua/NeutronVim/plugins/LSP/formatting.lua | 54 +++++++++++++++++++++++ lua/NeutronVim/plugins/LSP/linting.lua | 29 ++++++++++++ lua/NeutronVim/plugins/LSP/mason.lua | 38 +++++++++------- lua/NeutronVim/plugins/LSP/none-ls.lua | 46 ------------------- lua/NeutronVim/plugins/UI/lualine.lua | 17 +++++++ 5 files changed, 121 insertions(+), 63 deletions(-) create mode 100644 lua/NeutronVim/plugins/LSP/formatting.lua create mode 100644 lua/NeutronVim/plugins/LSP/linting.lua delete mode 100644 lua/NeutronVim/plugins/LSP/none-ls.lua diff --git a/lua/NeutronVim/plugins/LSP/formatting.lua b/lua/NeutronVim/plugins/LSP/formatting.lua new file mode 100644 index 0000000..8d48762 --- /dev/null +++ b/lua/NeutronVim/plugins/LSP/formatting.lua @@ -0,0 +1,54 @@ +return { + "stevearc/conform.nvim", + event = { "BufReadPre", "BufNewFile" }, + lazy = true, + keys = { + { + "mf", + "lua require('conform').format({lsp_fallback = true,async = false, timeout_ms = 500})", + mode = { "n", "v" }, + desc = "Format", + }, + }, + + config = function() + local conform_status_ok, conform = pcall(require, "conform") + if not conform_status_ok then + print("conform not found!") + end + conform.setup({ + formatters_by_ft = { + javascript = { "prettierd" }, + javascriptreact = { "prettierd" }, + typescript = { "prettierd" }, + typescriptreact = { "prettierd" }, + json = { "prettierd" }, + yaml = { "prettierd" }, + markdown = { "prettierd" }, + html = { "prettierd" }, + css = { "prettierd" }, + svelte = { "prettierd" }, + lua = { "stylua" }, + python = function(bufnr) + if require("conform").get_formatter_info("ruff_format", bufnr).available then + return { "ruff_format" } + else + return { "isort", "black" } + end + end, + rust = { "rustfmt" }, + cpp = { "clang-format" }, + c = { "clang-format" }, + cmake = { "cmake_format" }, + ["*"] = { "codespell" }, + fish = { "fish_indent" }, + sh = { "shfmt" }, + bash = { "shfmt" }, + }, + format_on_save = { + lsp_fallback = true, + async = true, + }, + }) + end, +} diff --git a/lua/NeutronVim/plugins/LSP/linting.lua b/lua/NeutronVim/plugins/LSP/linting.lua new file mode 100644 index 0000000..26f01ba --- /dev/null +++ b/lua/NeutronVim/plugins/LSP/linting.lua @@ -0,0 +1,29 @@ +return { + "daUnknownCoder/nvim-lint", + event = { "BufReadPre", "BufNewFile" }, + lazy = true, + keys = { + { "mt", "lua require('lint').try_lint()", desc = "Lint" }, + }, + config = function() + local linter_status_ok, lint = pcall(require, "lint") + if not linter_status_ok then + print("nvim-lint not found!") + end + lint.linters_by_ft = { + javascript = { "eslint_d" }, + javascriptreact = { "eslint_d" }, + typescript = { "eslint_d" }, + typescriptreact = { "eslint_d" }, + lua = { "luacheck" }, + python = { "pylint" }, + } + 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, + }) + end, +} diff --git a/lua/NeutronVim/plugins/LSP/mason.lua b/lua/NeutronVim/plugins/LSP/mason.lua index 0d90dce..bb26c72 100644 --- a/lua/NeutronVim/plugins/LSP/mason.lua +++ b/lua/NeutronVim/plugins/LSP/mason.lua @@ -4,18 +4,10 @@ return { lazy = true, dependencies = { { "williamboman/mason-lspconfig.nvim", cmd = { "LspInstall", "LspUninstall" } }, + { "WhoIsSethDaniel/mason-tool-installer.nvim" }, }, opts = { - ensure_installed = { - "black", - "isort", - "flake8", - "ruff", - "eslint_d", - "luacheck", - "prettierd", - "stylua", - }, + ensure_installed = {}, }, config = function() local icons_ok, icons = pcall(require, "NeutronVim.core.icons") @@ -30,11 +22,10 @@ return { if not mason_lspconfig_status_ok then print("mason-lspconfig not found!") end - local mason_null_ls_status_ok, mason_null_ls = pcall(require, "mason-null-ls") - if not mason_null_ls_status_ok then - print("mason-null-ls not found!") + local mason_tool_installer_status_ok, mason_tool_installer = pcall(require, "mason-tool-installer") + if not mason_tool_installer_status_ok then + print("mason-tool-installer not found!") end - mason.setup({ ui = { icons = { @@ -52,19 +43,32 @@ return { "lua_ls", "pyright", "marksman", + "eslint", + "clangd", + "cmake", + "bashls", }, automatic_installation = true, }) - mason_null_ls.setup({ + mason_tool_installer.setup({ ensure_installed = { "prettierd", + "eslint_d", "stylua", "black", "isort", - "ruff", - "eslint_d", + "pylint", "luacheck", + "ruff", + "rustfmt", + "clang-format", + "cmakelang", + "codespell", + "shfmt", }, + auto_update = true, + run_on_start = true, + start_delay = 5000, }) end, } diff --git a/lua/NeutronVim/plugins/LSP/none-ls.lua b/lua/NeutronVim/plugins/LSP/none-ls.lua deleted file mode 100644 index a92628a..0000000 --- a/lua/NeutronVim/plugins/LSP/none-ls.lua +++ /dev/null @@ -1,46 +0,0 @@ -return { - "nvimtools/none-ls.nvim", - dependencies = { - "jay-babu/mason-null-ls.nvim", - }, - event = "VimEnter", - lazy = true, - config = function() - local none_ls_status_ok, none_ls = pcall(require, "null-ls") - if not none_ls_status_ok then - print("none-ls not found!") - end - local formatting = none_ls.builtins.formatting - local diagnostics = none_ls.builtins.diagnostics - local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) - none_ls.setup({ - sources = { - formatting.black, - formatting.isort, - formatting.prettierd, - formatting.stylua, - diagnostics.eslint_d, - diagnostics.ruff, - diagnostics.luacheck, - }, - -- 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) - return client.name == "null-ls" - end, - bufnr = bufnr, - }) - end, - }) - end - end, - }) - end, -} diff --git a/lua/NeutronVim/plugins/UI/lualine.lua b/lua/NeutronVim/plugins/UI/lualine.lua index 291efe9..e646432 100644 --- a/lua/NeutronVim/plugins/UI/lualine.lua +++ b/lua/NeutronVim/plugins/UI/lualine.lua @@ -40,6 +40,18 @@ return { symbols = { modified = " " .. icons.ui.Pencil, readonly = " " .. icons.ui.Lock, unnamed = " [None] " }, path = 0, }, + { + function() + local lint_progress = function() + local linters = require("lint").get_running() + if #linters == 0 then + return "󰦕 Linting completed" + end + return "󱉶 Linting with '" .. table.concat(linters, ", ") .. "' in progress" + end + return lint_progress() + end, + }, { function() return "%=" @@ -73,6 +85,11 @@ return { }, }, lualine_x = { + { + function() + return "%=" + end, + }, { "diff", symbols = {