diff options
author | phanium <91544758+phanen@users.noreply.github.com> | 2025-03-16 20:49:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-16 05:49:05 -0700 |
commit | f5dd30948e67b0bfbfe0f1023a9b0c8a0b20b486 (patch) | |
tree | 064af071d0dd5de1493e386e7ca3bb98f785105b | |
parent | 7aae3f98de9ff8ee4371318ca223af0f51c5e08d (diff) | |
download | rneovim-f5dd30948e67b0bfbfe0f1023a9b0c8a0b20b486.tar.gz rneovim-f5dd30948e67b0bfbfe0f1023a9b0c8a0b20b486.tar.bz2 rneovim-f5dd30948e67b0bfbfe0f1023a9b0c8a0b20b486.zip |
fix(checkhealth): handle nested lua/ directory #32918
Problem: :checkhealth fails if plugin has nested "lua/" directory
Solution: trim `{runtimepath}/lua` from fullpath to get subpath
(`./**/{health, health/init.lua}`)
-rw-r--r-- | runtime/lua/vim/health.lua | 8 | ||||
-rw-r--r-- | test/functional/fixtures/lua/test_plug/lua/health.lua | 8 | ||||
-rw-r--r-- | test/functional/plugin/health_spec.lua | 12 |
3 files changed, 27 insertions, 1 deletions
diff --git a/runtime/lua/vim/health.lua b/runtime/lua/vim/health.lua index 0d42e8fed6..75cbfdef4a 100644 --- a/runtime/lua/vim/health.lua +++ b/runtime/lua/vim/health.lua @@ -118,7 +118,13 @@ local function filepath_to_healthcheck(path) func = 'health#' .. name .. '#check' filetype = 'v' else - local subpath = path:gsub('.*/lua/', '') + local rtp = vim + .iter(vim.api.nvim_list_runtime_paths()) + :map(vim.fs.normalize) + :find(function(rtp0) + return vim.fs.relpath(rtp0, path) + end) + local subpath = path:gsub('^' .. vim.pesc(rtp .. '/lua/'), '') if vim.fs.basename(subpath) == 'health.lua' then -- */health.lua name = vim.fs.dirname(subpath) diff --git a/test/functional/fixtures/lua/test_plug/lua/health.lua b/test/functional/fixtures/lua/test_plug/lua/health.lua new file mode 100644 index 0000000000..75164f37ab --- /dev/null +++ b/test/functional/fixtures/lua/test_plug/lua/health.lua @@ -0,0 +1,8 @@ +local M = {} + +M.check = function() + vim.health.start('nested lua/ directory') + vim.health.ok('everything is ok') +end + +return M diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 406b5c3c16..1f754b9685 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -212,6 +212,18 @@ describe('vim.health', function() n.expect([[ ERROR: No healthchecks found.]]) end) + + it('nested lua/ directory', function() + command('checkhealth lua') + n.expect([[ + + ============================================================================== + test_plug.lua: require("test_plug.lua.health").check() + + nested lua/ directory ~ + - OK everything is ok + ]]) + end) end) end) |