mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-21 20:11:06 +00:00
## Description
`mason-lspconfig` v2 made changes to conform with latest Neovim
`vim.lsp.config`/`vim.lsp.enable` API.
- Lock `mason` and `mason-lspconfig` to v1 versions for Neovim <0.11 and
latest HEAD for Neovim >=0.11.
- Change `:get_install_path()` method in LazyVim to use
`LazyVim.get_pkg_path()` and also update name references to new ones.
- Change `nvim-lspconfig` from `LazyFile` to `{ "BufReadPre",
"BufNewFile", "BufWritePre" }` for Neovim >=0.11, since on `BufReadPost`
the LSP would not attach on the first buffer. Previously the
`setup.handlers()` function from `mason-lspconfig` would take care of
that, but that has been removed on v2. I fail to think if there's a
better way to handle this.
Most of the changes in `/lsp/init.lua` are thanks to @williamboman
comment
[here](https://github.com/LazyVim/LazyVim/pull/6041#issuecomment-2857266471).
I've also seen that both `mason-lspconfig` and `rustaceanvim` now have
as minimum requirements Neovim >=0.11.
As such I would suggest, instead of all the conditional checks for
Neovim versions to create a stable release where we pin `mason` and
`mason-lspconfig` to v1 versions and then only incorporate William's
suggestions in a new release and mention in the README that users who
are on Neovim <0.11 should use the stable release where the plugin
versions are pinned to v1. Not sure how you want to tackle this, so this
is merely just a suggestion from my part.
Both #6041 and #6045 tackle only with the new name references and the
offending line that was causing the error, but don't take into
consideration the LSP servers configurations. `opts.setup` would not
execute on both, since that was handled by `setup_handlers()` function
in the past. I checked with Typescript lang and with those PRs there are
no Javascript settings in `vtsls` (by checking with
`:=LazyVim.opts("nvim-lspconfig").servers.vtsls`).
#6045 also tried to change the method `:get_install_pkg()` by using
`vim.fn.exepath`, but to my understanding that only returns the binary
path not the package installation path and that is later concatenated to
find other paths, which I believe is not correct.
PS: There are 2 commits, because my LazyVim fork was not up to date and
updated it and then merged the branch I had into a new branch. Sorry if
that causes any inconvenience.
<!-- Describe the big picture of your changes to communicate to the
maintainers
why we should accept this pull request. -->
## Related Issue(s)
Fixes #6039
<!--
If this PR fixes any issues, please link to the issue here.
- Fixes #<issue_number>
-->
## Screenshots
<!-- Add screenshots of the changes if applicable. -->
## Checklist
- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
---------
Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
Co-authored-by: William Boman <william@redwill.se>
Co-authored-by: Luis Durão <kpvrzlzzx@mozmail.com>
128 lines
4.5 KiB
Lua
128 lines
4.5 KiB
Lua
---@module 'luassert'
|
|
|
|
local Icons = require("mini.icons")
|
|
|
|
local Plugin = require("lazy.core.plugin")
|
|
_G.LazyVim = require("lazyvim.util")
|
|
|
|
describe("Extra", function()
|
|
local Config = require("lazy.core.config")
|
|
assert(vim.tbl_count(Config.plugins) > 0, "Lazy not properly setup")
|
|
|
|
---@type {modname:string, modpath:string}[]
|
|
local extras = vim.tbl_map(
|
|
---@param path string
|
|
function(path)
|
|
local modname = path:sub(5):gsub("%.lua$", ""):gsub("/", ".")
|
|
return { modname = modname, modpath = path }
|
|
end,
|
|
vim.fs.find(function(name)
|
|
return name:match("%.lua$")
|
|
end, { limit = math.huge, type = "file", path = "lua/lazyvim/plugins/extras" })
|
|
)
|
|
|
|
local ignore = { "lazyvim.plugins.extras.ui.treesitter-rewrite" }
|
|
extras = vim.tbl_filter(function(extra)
|
|
return not vim.tbl_contains(ignore, extra.modname)
|
|
end, extras)
|
|
|
|
local lsp_to_pkg = {}
|
|
lsp_to_pkg = require("mason-lspconfig.mappings").get_mason_map().lspconfig_to_package
|
|
|
|
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
|
|
local name = extra.modname:sub(#"lazyvim.plugins.extras" + 2)
|
|
describe(name, function()
|
|
it("spec is valid", function()
|
|
local mod = require(extra.modname)
|
|
assert.is_not_nil(mod)
|
|
local spec = Plugin.Spec.new({
|
|
{ "mason-org/mason.nvim", opts = { ensure_installed = {} } },
|
|
{ "nvim-treesitter/nvim-treesitter", opts = { ensure_installed = {} } },
|
|
mod,
|
|
}, { optional = true })
|
|
assert(#spec.notifs == 0, "Invalid spec: " .. vim.inspect(spec.notifs))
|
|
end)
|
|
|
|
if extra.modname:find("%.lang%.") then
|
|
it("has recommended set", function()
|
|
local mod = require(extra.modname)
|
|
assert(mod.recommended, "`recommended` not set for " .. extra.modname)
|
|
end)
|
|
end
|
|
|
|
local mod = require(extra.modname)
|
|
local spec = Plugin.Spec.new({
|
|
{ "mason-org/mason.nvim", opts = { ensure_installed = {} } },
|
|
{ "nvim-treesitter/nvim-treesitter", opts = { ensure_installed = {} } },
|
|
mod,
|
|
}, { optional = true })
|
|
local lspconfig = spec.plugins["nvim-lspconfig"]
|
|
if lspconfig then
|
|
it("does not install LSP servers with mason.nvim", function()
|
|
local lspconfig_opts = Plugin.values(lspconfig, "opts", false)
|
|
local mason = spec.plugins["mason.nvim"]
|
|
local mason_opts = Plugin.values(mason, "opts", false)
|
|
|
|
for lsp in pairs(lspconfig_opts.servers or {}) do
|
|
local lsp_pkg = lsp_to_pkg[lsp]
|
|
assert(
|
|
not (lsp_pkg and vim.tbl_contains(mason_opts.ensure_installed, lsp_pkg)),
|
|
"LSP server "
|
|
.. lsp
|
|
.. " with pkg "
|
|
.. (lsp_pkg or "foo")
|
|
.. " is installed automatically. Please remove from the mason.nvim spec"
|
|
)
|
|
end
|
|
end)
|
|
end
|
|
|
|
local ts = spec.plugins["nvim-treesitter"]
|
|
local opts = Plugin.values(ts, "opts", false)
|
|
|
|
if not vim.tbl_isempty(opts.ensure_installed) then
|
|
it("does not install default Treesitter langs", function()
|
|
local invalid = vim.tbl_filter(function(v)
|
|
return vim.tbl_contains(tsensure, v)
|
|
end, opts.ensure_installed or {})
|
|
assert.same(
|
|
{},
|
|
invalid,
|
|
"These Treesitter langs are installed by default. Please remove them from the extra."
|
|
)
|
|
end)
|
|
end
|
|
|
|
-- Icons
|
|
local icons = spec.plugins["mini.icons"]
|
|
if icons then
|
|
local icon_opts = Plugin.values(icons, "opts", false) or {}
|
|
local cats = { "directory", "file", "extension", "filetype", "lsp", "os" }
|
|
for _, cat in ipairs(cats) do
|
|
local cat_names = Icons.list(cat)
|
|
if icon_opts[cat] then
|
|
describe("does not set existing icons for " .. cat, function()
|
|
for icon_name in pairs(icon_opts[cat]) do
|
|
it(icon_name, function()
|
|
assert.is_false(
|
|
vim.tbl_contains(cat_names, icon_name),
|
|
"Icon " .. icon_name .. " already exists:\n" .. vim.inspect({ Icons.get(cat, icon_name) })
|
|
)
|
|
end)
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
end
|
|
end)
|
|
end
|
|
end)
|