mirror of
https://github.com/neovim/neovim
synced 2025-07-18 10:11:50 +00:00
fix(checkhealth): mitigate issues with duplicate healthchecks #15919
* fix(runtime/health): mitigate issues with duplicate healthchecks Previously if a healthcheck was found as Lua and Vim it was executed both times. This new implementations prefers Lua, therefore if two are found It only runs the Lua one, this way a plugin can mantain both implementations the Lua one with the method `check()` and the autoload function `#check()` (for none HEAD nvim versions). **Note: This will require plugins to use `check()` as the function name, since the autoload function that wraps the lua implementation won't be called** * docs(health): use spaces and don't overuse backtics followup to #15259
This commit is contained in:
@ -41,8 +41,8 @@ function! health#check(plugin_names) abort
|
|||||||
call setline(1, 'ERROR: No healthchecks found.')
|
call setline(1, 'ERROR: No healthchecks found.')
|
||||||
else
|
else
|
||||||
redraw|echo 'Running healthchecks...'
|
redraw|echo 'Running healthchecks...'
|
||||||
for c in healthchecks
|
for name in sort(keys(healthchecks))
|
||||||
let [name, func, type] = c
|
let [func, type] = healthchecks[name]
|
||||||
let s:output = []
|
let s:output = []
|
||||||
try
|
try
|
||||||
if func == ''
|
if func == ''
|
||||||
@ -176,8 +176,30 @@ function! s:discover_healthchecks() abort
|
|||||||
return s:get_healthcheck('*')
|
return s:get_healthcheck('*')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Returns list of lists [ [{name}, {func}, {type}] ] representing healthchecks
|
" Returns Dictionary {name: [func, type], ..} representing healthchecks
|
||||||
function! s:get_healthcheck(plugin_names) abort
|
function! s:get_healthcheck(plugin_names) abort
|
||||||
|
let health_list = s:get_healthcheck_list(a:plugin_names)
|
||||||
|
let healthchecks = {}
|
||||||
|
for c in health_list
|
||||||
|
let name = c[0]
|
||||||
|
let existent = get(healthchecks, name, [])
|
||||||
|
" If an entry with the same name exists and is from vim, prefer Lua so
|
||||||
|
" overwrite it.
|
||||||
|
if existent != []
|
||||||
|
if existent[1] == "v"
|
||||||
|
let healthchecks[name] = c[1:]
|
||||||
|
else
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let healthchecks[name] = c[1:]
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return healthchecks
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Returns list of lists [ [{name}, {func}, {type}] ] representing healthchecks
|
||||||
|
function! s:get_healthcheck_list(plugin_names) abort
|
||||||
let healthchecks = []
|
let healthchecks = []
|
||||||
let plugin_names = type('') == type(a:plugin_names)
|
let plugin_names = type('') == type(a:plugin_names)
|
||||||
\ ? split(a:plugin_names, ' ', v:false)
|
\ ? split(a:plugin_names, ' ', v:false)
|
||||||
|
@ -83,14 +83,14 @@ will automatically find and invoke this function.
|
|||||||
|
|
||||||
If your plugin is named "foo", then its healthcheck module should be a file in
|
If your plugin is named "foo", then its healthcheck module should be a file in
|
||||||
one of these locations on 'runtimepath' or 'packpath':
|
one of these locations on 'runtimepath' or 'packpath':
|
||||||
- `lua/foo/health/init.lua`
|
- lua/foo/health/init.lua
|
||||||
- `lua/foo/health.lua`
|
- lua/foo/health.lua
|
||||||
|
|
||||||
If your plugin provides a submodule named "bar" for which you want a separate
|
If your plugin provides a submodule named "bar" for which you want a separate
|
||||||
healthcheck, define the healthcheck at one of these locations on 'runtimepath'
|
healthcheck, define the healthcheck at one of these locations on 'runtimepath'
|
||||||
or 'packpath':
|
or 'packpath':
|
||||||
- `lua/foo/bar/health/init.lua`
|
- lua/foo/bar/health/init.lua
|
||||||
- `lua/foo/bar/health.lua`
|
- lua/foo/bar/health.lua
|
||||||
|
|
||||||
All submodules should return a Lua table containing the method `check()`.
|
All submodules should return a Lua table containing the method `check()`.
|
||||||
|
|
||||||
@ -159,8 +159,8 @@ health#{plugin}#check() function in autoload/health/{plugin}.vim.
|
|||||||
If your plugin is named "foo", then its healthcheck function must be >
|
If your plugin is named "foo", then its healthcheck function must be >
|
||||||
health#foo#check()
|
health#foo#check()
|
||||||
|
|
||||||
defined in this file on 'runtimepath' or 'packpath': >
|
defined in this file on 'runtimepath' or 'packpath':
|
||||||
autoload/health/foo.vim
|
- autoload/health/foo.vim
|
||||||
|
|
||||||
Copy this sample code into autoload/health/foo.vim and replace "foo" with your
|
Copy this sample code into autoload/health/foo.vim and replace "foo" with your
|
||||||
plugin name: >
|
plugin name: >
|
||||||
@ -177,4 +177,4 @@ plugin name: >
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
vim:noet tw=78:ts=8:ft=help:fdm=marker
|
vim:et:tw=78:ts=8:ft=help:fdm=marker
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
function! health#success1#check()
|
||||||
|
call health#report_start("If you see this I'm broken")
|
||||||
|
endfunction
|
@ -100,8 +100,10 @@ describe('health.vim', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("lua plugins", function()
|
it("lua plugins, skips vimscript healthchecks with the same name", function()
|
||||||
command("checkhealth test_plug")
|
command("checkhealth test_plug")
|
||||||
|
-- Existing file in test/functional/fixtures/lua/test_plug/autoload/health/test_plug.vim
|
||||||
|
-- and the Lua healthcheck is used instead.
|
||||||
helpers.expect([[
|
helpers.expect([[
|
||||||
|
|
||||||
test_plug: require("test_plug.health").check()
|
test_plug: require("test_plug.health").check()
|
||||||
|
Reference in New Issue
Block a user