From 368c060b45f260c34b87e17fe9a7d0f26992110c Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 5 Jun 2024 17:47:46 +0200 Subject: [PATCH] tests: check for treesitter langs and mason lsp config --- tests/extras/lang_spec.lua | 33 ++++++++++++++++++++++++++++++++- tests/init.lua | 2 ++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/extras/lang_spec.lua b/tests/extras/lang_spec.lua index 8a99ec3b..7a58be5c 100644 --- a/tests/extras/lang_spec.lua +++ b/tests/extras/lang_spec.lua @@ -5,6 +5,7 @@ _G.LazyVim = require("lazyvim.util") describe("Extra", function() local Config = require("lazy.core.config") + local Loader = require("lazy.core.loader") assert(vim.tbl_count(Config.plugins) > 0, "Lazy not properly setup") ---@type {modname:string, modpath:string}[] @@ -18,16 +19,46 @@ describe("Extra", function() return name:match("%.lua$") end, { limit = math.huge, type = "file", path = "lua/lazyvim/plugins/extras" }) ) + local servers = require("mason-lspconfig.mappings.server").package_to_lspconfig + + local tsspec = Plugin.Spec.new({ + import = "lazyvim.plugins.treesitter", + }, { optional = true }) + + local tsopts = Plugin.values(tsspec.plugins["nvim-treesitter"], "opts", false) + + local tsensure = tsopts.ensure_installed + assert(type(tsensure) == "table", "No ensure_installed in nvim-treesitter spec") for _, extra in ipairs(extras) do it(extra.modname .. " is valid", function() local mod = require(extra.modname) - local spec = Plugin.Spec.new(mod, { optional = true }) + local spec = Plugin.Spec.new({ + { "williamboman/mason.nvim", opts = { ensure_installed = {} } }, + { "nvim-treesitter/nvim-treesitter", opts = { ensure_installed = {} } }, + mod, + }, { optional = true }) assert.is_not_nil(mod) assert(#spec.notifs == 0, "Invalid spec: " .. vim.inspect(spec.notifs)) if extra.modname:find("%.lang%.") then assert(mod.recommended, "`recommended` not set for " .. extra.modname) + local mason = spec.plugins["mason.nvim"] + local opts = Plugin.values(mason, "opts", false) + for _, v in ipairs(opts.ensure_installed) do + assert( + not servers[v], + "LSP server " .. v .. " is installed automatically. Please remove from the mason.nvim spec" + ) + end + local ts = spec.plugins["nvim-treesitter"] + opts = Plugin.values(mason, "opts", false) + for _, v in ipairs(opts.ensure_installed) do + assert( + not vim.tbl_contains(tsensure, v), + "TS lang " .. v .. " is already a default. Please remove from the mason.nvim spec" + ) + end end end) end diff --git a/tests/init.lua b/tests/init.lua index 8132688a..ca44aab6 100644 --- a/tests/init.lua +++ b/tests/init.lua @@ -19,6 +19,8 @@ local plugins = { "LazyVim/starter", { "nvim-lua/plenary.nvim" }, { "folke/lazy.nvim" }, + "williamboman/mason-lspconfig.nvim", + "williamboman/mason.nvim", } local function main()