From c48cf1875225310feb8d656cf42c5d817b7e150e Mon Sep 17 00:00:00 2001 From: phanium <91544758+phanen@users.noreply.github.com> Date: Wed, 19 Mar 2025 22:48:28 +0800 Subject: 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). --- runtime/lua/vim/health.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/runtime/lua/vim/health.lua b/runtime/lua/vim/health.lua index 75cbfdef4a..c790779d51 100644 --- a/runtime/lua/vim/health.lua +++ b/runtime/lua/vim/health.lua @@ -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) -- cgit