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:
phanium
2025-03-19 22:48:28 +08:00
committed by GitHub
parent 424f4cc038
commit c48cf18752

View File

@ -109,7 +109,7 @@ local s_output = {} ---@type string[]
-- From a path return a list [{name}, {func}, {type}] representing a healthcheck -- From a path return a list [{name}, {func}, {type}] representing a healthcheck
local function filepath_to_healthcheck(path) local function filepath_to_healthcheck(path)
path = vim.fs.normalize(path) path = vim.fs.abspath(vim.fs.normalize(path))
local name --- @type string local name --- @type string
local func --- @type string local func --- @type string
local filetype --- @type string local filetype --- @type string
@ -118,13 +118,17 @@ local function filepath_to_healthcheck(path)
func = 'health#' .. name .. '#check' func = 'health#' .. name .. '#check'
filetype = 'v' filetype = 'v'
else else
local rtp = vim local rtp_lua = vim
.iter(vim.api.nvim_list_runtime_paths()) .iter(vim.api.nvim_get_runtime_file('lua/', true))
:map(vim.fs.normalize) :map(function(rtp_lua)
:find(function(rtp0) return vim.fs.abspath(vim.fs.normalize(rtp_lua))
return vim.fs.relpath(rtp0, path)
end) 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 if vim.fs.basename(subpath) == 'health.lua' then
-- */health.lua -- */health.lua
name = vim.fs.dirname(subpath) name = vim.fs.dirname(subpath)