From 7e5d166d9b53a56c5b55c32c2ef977799d9a5963 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Wed, 7 Feb 2024 12:15:52 -0500 Subject: [PATCH 1/2] feat(nvim-lint): disable `diagnostic` types in `mason-null-ls` setup if it's available --- lua/astrocommunity/lsp/nvim-lint/init.lua | 87 ++++++++++++----------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/lua/astrocommunity/lsp/nvim-lint/init.lua b/lua/astrocommunity/lsp/nvim-lint/init.lua index 1cfceba1d..0b4f4eff3 100644 --- a/lua/astrocommunity/lsp/nvim-lint/init.lua +++ b/lua/astrocommunity/lsp/nvim-lint/init.lua @@ -1,51 +1,54 @@ ---@type LazySpec return { - "mfussenegger/nvim-lint", - event = "User AstroFile", - dependencies = { "williamboman/mason.nvim" }, - opts = {}, - config = function(_, opts) - local lint = require "lint" + { "jay-babu/mason-null-ls.nvim", optional = true, opts = { methods = { diagnostics = false } } }, + { + "mfussenegger/nvim-lint", + event = "User AstroFile", + dependencies = { "williamboman/mason.nvim" }, + opts = {}, + config = function(_, opts) + local lint = require "lint" - lint.linters_by_ft = opts.linters_by_ft or {} - for name, linter in pairs(opts.linters or {}) do - local base = lint.linters[name] - lint.linters[name] = (type(linter) == "table" and type(base) == "table") - and vim.tbl_deep_extend("force", base, linter) - or linter - end + lint.linters_by_ft = opts.linters_by_ft or {} + for name, linter in pairs(opts.linters or {}) do + local base = lint.linters[name] + lint.linters[name] = (type(linter) == "table" and type(base) == "table") + and vim.tbl_deep_extend("force", base, linter) + or linter + end - local function try_lint() - local names = lint._resolve_linter_by_ft(vim.bo.filetype) + local function try_lint() + local names = lint._resolve_linter_by_ft(vim.bo.filetype) - -- Add fallback linters and global linters. - if #names == 0 then names = lint.linters_by_ft["_"] or {} end - vim.list_extend(names, lint.linters_by_ft["*"] or {}) + -- Add fallback linters and global linters. + if #names == 0 then names = lint.linters_by_ft["_"] or {} end + vim.list_extend(names, lint.linters_by_ft["*"] or {}) - -- Filter out linters that don't exist or don't match the condition. - local ctx = { filename = vim.api.nvim_buf_get_name(0) } - ctx.dirname = vim.fn.fnamemodify(ctx.filename, ":h") - names = vim.tbl_filter(function(name) - local linter = lint.linters[name] - return linter - and vim.fn.executable(linter.cmd) == 1 - and not (type(linter) == "table" and linter.condition and not linter.condition(ctx)) - end, names) + -- Filter out linters that don't exist or don't match the condition. + local ctx = { filename = vim.api.nvim_buf_get_name(0) } + ctx.dirname = vim.fn.fnamemodify(ctx.filename, ":h") + names = vim.tbl_filter(function(name) + local linter = lint.linters[name] + return linter + and vim.fn.executable(linter.cmd) == 1 + and not (type(linter) == "table" and linter.condition and not linter.condition(ctx)) + end, names) - lint.try_lint(names) - end + lint.try_lint(names) + end - try_lint() -- start linter immediately - local timer = vim.loop.new_timer() - vim.api.nvim_create_autocmd({ "BufWritePost", "BufReadPost", "InsertLeave", "TextChanged" }, { - group = vim.api.nvim_create_augroup("auto_lint", { clear = true }), - desc = "Automatically try linting", - callback = function() - timer:start(100, 0, function() - timer:stop() - vim.schedule(try_lint) - end) - end, - }) - end, + try_lint() -- start linter immediately + local timer = vim.loop.new_timer() + vim.api.nvim_create_autocmd({ "BufWritePost", "BufReadPost", "InsertLeave", "TextChanged" }, { + group = vim.api.nvim_create_augroup("auto_lint", { clear = true }), + desc = "Automatically try linting", + callback = function() + timer:start(100, 0, function() + timer:stop() + vim.schedule(try_lint) + end) + end, + }) + end, + }, } From 9c314b71d5889a31a552243af4ea34445a6a7591 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Wed, 7 Feb 2024 12:16:20 -0500 Subject: [PATCH 2/2] feat(conform-nvim): disable `formatting` types in `mason-null-ls` setup if it's available --- lua/astrocommunity/editing-support/conform-nvim/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/astrocommunity/editing-support/conform-nvim/init.lua b/lua/astrocommunity/editing-support/conform-nvim/init.lua index 57c3233e2..9aedc642a 100644 --- a/lua/astrocommunity/editing-support/conform-nvim/init.lua +++ b/lua/astrocommunity/editing-support/conform-nvim/init.lua @@ -1,5 +1,6 @@ return { { "AstroNvim/astrolsp", opts = { formatting = { disabled = true } } }, + { "jay-babu/mason-null-ls.nvim", optional = true, opts = { methods = { formatting = false } } }, { "stevearc/conform.nvim", event = "User AstroFile",