mirror of
https://github.com/neovim/neovim
synced 2025-07-15 16:51:49 +00:00
fix(checkhealth): module not found when &rtp
has nested paths #32988
Problem: `:checkhealth` fail to find the module when `&rtp` have nested paths. Solution: find in order all existed `&rtp/lua` path rather than `&rtp` to ensure prefix exist before trim `&rtp`. In this case one module can be searched out from two different `&rtp/lua`, we use the first `&rtp/lua` contain the module (like how require() works).
This commit is contained in:
@ -109,7 +109,7 @@ local s_output = {} ---@type string[]
|
||||
|
||||
-- From a path return a list [{name}, {func}, {type}] representing a healthcheck
|
||||
local function filepath_to_healthcheck(path)
|
||||
path = vim.fs.normalize(path)
|
||||
path = vim.fs.abspath(vim.fs.normalize(path))
|
||||
local name --- @type string
|
||||
local func --- @type string
|
||||
local filetype --- @type string
|
||||
@ -118,13 +118,17 @@ local function filepath_to_healthcheck(path)
|
||||
func = 'health#' .. name .. '#check'
|
||||
filetype = 'v'
|
||||
else
|
||||
local rtp = vim
|
||||
.iter(vim.api.nvim_list_runtime_paths())
|
||||
:map(vim.fs.normalize)
|
||||
:find(function(rtp0)
|
||||
return vim.fs.relpath(rtp0, path)
|
||||
local rtp_lua = vim
|
||||
.iter(vim.api.nvim_get_runtime_file('lua/', true))
|
||||
:map(function(rtp_lua)
|
||||
return vim.fs.abspath(vim.fs.normalize(rtp_lua))
|
||||
end)
|
||||
local subpath = path:gsub('^' .. vim.pesc(rtp .. '/lua/'), '')
|
||||
:find(function(rtp_lua)
|
||||
return vim.fs.relpath(rtp_lua, path)
|
||||
end)
|
||||
-- "/path/to/rtp/lua/foo/bar/health.lua" => "foo/bar/health.lua"
|
||||
-- "/another/rtp/lua/baz/health/init.lua" => "baz/health/init.lua"
|
||||
local subpath = path:gsub('^' .. vim.pesc(rtp_lua), ''):gsub('^/+', '')
|
||||
if vim.fs.basename(subpath) == 'health.lua' then
|
||||
-- */health.lua
|
||||
name = vim.fs.dirname(subpath)
|
||||
|
Reference in New Issue
Block a user