diff options
author | phanium <91544758+phanen@users.noreply.github.com> | 2025-03-19 22:48:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-19 07:48:28 -0700 |
commit | c48cf1875225310feb8d656cf42c5d817b7e150e (patch) | |
tree | 484297b0a97ebab82f345f7081afafe4cafa1e91 | |
parent | 424f4cc0389ed883f220bd5cbab9c07b4955acde (diff) | |
download | rneovim-c48cf1875225310feb8d656cf42c5d817b7e150e.tar.gz rneovim-c48cf1875225310feb8d656cf42c5d817b7e150e.tar.bz2 rneovim-c48cf1875225310feb8d656cf42c5d817b7e150e.zip |
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).
-rw-r--r-- | runtime/lua/vim/health.lua | 18 |
1 files 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) |