aboutsummaryrefslogtreecommitdiff
path: root/runtime/autoload
diff options
context:
space:
mode:
authorJavier Lopez <graulopezjavier@gmail.com>2021-10-05 17:37:39 -0500
committerGitHub <noreply@github.com>2021-10-05 15:37:39 -0700
commitacd5e831b6294e54b12c09983bee3da89c0f183a (patch)
treeb8817b289ab051f4df080282e414399d2a45d4c7 /runtime/autoload
parent6a930a9dc4ddf190b528c945f19bc0a0bad2cc29 (diff)
downloadrneovim-acd5e831b6294e54b12c09983bee3da89c0f183a.tar.gz
rneovim-acd5e831b6294e54b12c09983bee3da89c0f183a.tar.bz2
rneovim-acd5e831b6294e54b12c09983bee3da89c0f183a.zip
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
Diffstat (limited to 'runtime/autoload')
-rw-r--r--runtime/autoload/health.vim28
1 files changed, 25 insertions, 3 deletions
diff --git a/runtime/autoload/health.vim b/runtime/autoload/health.vim
index 17047707fb..579db62cb8 100644
--- a/runtime/autoload/health.vim
+++ b/runtime/autoload/health.vim
@@ -41,8 +41,8 @@ function! health#check(plugin_names) abort
call setline(1, 'ERROR: No healthchecks found.')
else
redraw|echo 'Running healthchecks...'
- for c in healthchecks
- let [name, func, type] = c
+ for name in sort(keys(healthchecks))
+ let [func, type] = healthchecks[name]
let s:output = []
try
if func == ''
@@ -176,8 +176,30 @@ function! s:discover_healthchecks() abort
return s:get_healthcheck('*')
endfunction
-" Returns list of lists [ [{name}, {func}, {type}] ] representing healthchecks
+" Returns Dictionary {name: [func, type], ..} representing healthchecks
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 plugin_names = type('') == type(a:plugin_names)
\ ? split(a:plugin_names, ' ', v:false)