diff options
Diffstat (limited to 'runtime/autoload')
-rw-r--r-- | runtime/autoload/health.vim | 126 | ||||
-rw-r--r-- | runtime/autoload/health/lsp.vim | 5 | ||||
-rw-r--r-- | runtime/autoload/health/treesitter.vim | 5 | ||||
-rw-r--r-- | runtime/autoload/netrw.vim | 3 | ||||
-rw-r--r-- | runtime/autoload/provider/pythonx.vim | 2 |
5 files changed, 88 insertions, 53 deletions
diff --git a/runtime/autoload/health.vim b/runtime/autoload/health.vim index 0f7983f175..73c1459f86 100644 --- a/runtime/autoload/health.vim +++ b/runtime/autoload/health.vim @@ -26,8 +26,8 @@ endfunction " Runs all discovered healthchecks if a:plugin_names is empty. function! health#check(plugin_names) abort let healthchecks = empty(a:plugin_names) - \ ? s:discover_health_checks() - \ : s:to_fn_names(a:plugin_names) + \ ? s:discover_healthchecks() + \ : s:get_healthcheck(a:plugin_names) tabnew setlocal wrap breakindent linebreak @@ -41,25 +41,29 @@ function! health#check(plugin_names) abort call setline(1, 'ERROR: No healthchecks found.') else redraw|echo 'Running healthchecks...' - for c in healthchecks - let output = '' - call append('$', split(printf("\n%s\n%s", c, repeat('=',72)), "\n")) + for name in sort(keys(healthchecks)) + let [func, type] = healthchecks[name] + let s:output = [] try - let output = "\n\n".execute('call '.c.'()') + if func == '' + throw 'healthcheck_not_found' + endif + eval type == 'v' ? call(func, []) : luaeval(func) catch - if v:exception =~# '^Vim\%((\a\+)\)\=:E117.*\V'.c - let output = execute( - \ 'call health#report_error(''No healthcheck found for "' - \ .s:to_plugin_name(c) - \ .'" plugin.'')') + let s:output = [] " Clear the output + if v:exception =~# 'healthcheck_not_found' + call health#report_error('No healthcheck found for "'.name.'" plugin.') else - let output = execute( - \ 'call health#report_error(''Failed to run healthcheck for "' - \ .s:to_plugin_name(c) - \ .'" plugin. Exception:''."\n".v:throwpoint."\n".v:exception)') + call health#report_error(printf( + \ "Failed to run healthcheck for \"%s\" plugin. Exception:\n%s\n%s", + \ name, v:throwpoint, v:exception)) endif endtry - call append('$', split(output, "\n") + ['']) + let header = [name. ': ' . func, repeat('=', 72)] + " remove empty line after header from report_start + let s:output = s:output[0] == '' ? s:output[1:] : s:output + let s:output = header + s:output + [''] + call append('$', s:output) redraw endfor endif @@ -71,9 +75,13 @@ function! health#check(plugin_names) abort redraw|echo '' endfunction +function! s:collect_output(output) + let s:output += split(a:output, "\n", 1) +endfunction + " Starts a new report. function! health#report_start(name) abort - echo "\n## " . a:name + call s:collect_output("\n## " . a:name) endfunction " Indents lines *except* line 1 of a string if it contains newlines. @@ -119,21 +127,21 @@ endfunction " }}} " Use {msg} to report information in the current section function! health#report_info(msg) abort " {{{ - echo s:format_report_message('INFO', a:msg) + call s:collect_output(s:format_report_message('INFO', a:msg)) endfunction " }}} " Reports a successful healthcheck. function! health#report_ok(msg) abort " {{{ - echo s:format_report_message('OK', a:msg) + call s:collect_output(s:format_report_message('OK', a:msg)) endfunction " }}} " Reports a health warning. " a:1: Optional advice (string or list) function! health#report_warn(msg, ...) abort " {{{ if a:0 > 0 - echo s:format_report_message('WARNING', a:msg, a:1) + call s:collect_output(s:format_report_message('WARNING', a:msg, a:1)) else - echo s:format_report_message('WARNING', a:msg) + call s:collect_output(s:format_report_message('WARNING', a:msg)) endif endfunction " }}} @@ -141,37 +149,73 @@ endfunction " }}} " a:1: Optional advice (string or list) function! health#report_error(msg, ...) abort " {{{ if a:0 > 0 - echo s:format_report_message('ERROR', a:msg, a:1) + call s:collect_output(s:format_report_message('ERROR', a:msg, a:1)) else - echo s:format_report_message('ERROR', a:msg) + call s:collect_output(s:format_report_message('ERROR', a:msg)) endif endfunction " }}} -function! s:filepath_to_function(name) abort - return substitute(substitute(substitute(a:name, '.*autoload[\/]', '', ''), - \ '\.vim', '#check', ''), '[\/]', '#', 'g') +" From a path return a list [{name}, {func}, {type}] representing a healthcheck +function! s:filepath_to_healthcheck(path) abort + if a:path =~# 'vim$' + let name = matchstr(a:path, '\zs[^\/]*\ze\.vim$') + let func = 'health#'.name.'#check' + let type = 'v' + else + let base_path = substitute(a:path, + \ '.*lua[\/]\(.\{-}\)[\/]health\([\/]init\)\?\.lua$', + \ '\1', '') + let name = substitute(base_path, '[\/]', '.', 'g') + let func = 'require("'.name.'.health").check()' + let type = 'l' + endif + return [name, func, type] endfunction -function! s:discover_health_checks() abort - let healthchecks = globpath(&runtimepath, 'autoload/health/*.vim', 1, 1) - let healthchecks = map(healthchecks, '<SID>filepath_to_function(v:val)') - return healthchecks +function! s:discover_healthchecks() abort + return s:get_healthcheck('*') +endfunction + +" 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 normalized_name = substitute(c[0], '-', '_', 'g') + let existent = get(healthchecks, normalized_name, []) + " Prefer Lua over vim entries + if existent != [] && existent[2] == 'l' + continue + else + let healthchecks[normalized_name] = c + endif + endfor + let output = {} + for v in values(healthchecks) + let output[v[0]] = v[1:] + endfor + return output endfunction -" Translates a list of plugin names to healthcheck function names. -function! s:to_fn_names(plugin_names) abort +" 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) + let plugin_names = type('') == type(a:plugin_names) + \ ? split(a:plugin_names, ' ', v:false) \ : a:plugin_names for p in plugin_names - call add(healthchecks, 'health#'.p.'#check') + " support vim/lsp/health{/init/}.lua as :checkhealth vim.lsp + let p = substitute(p, '\.', '/', 'g') + let p = substitute(p, '*$', '**', 'g') " find all submodule e.g vim* + let paths = nvim_get_runtime_file('autoload/health/'.p.'.vim', v:true) + \ + nvim_get_runtime_file('lua/**/'.p.'/health/init.lua', v:true) + \ + nvim_get_runtime_file('lua/**/'.p.'/health.lua', v:true) + if len(paths) == 0 + let healthchecks += [[p, '', '']] " healthchek not found + else + let healthchecks += map(uniq(sort(paths)), + \'<SID>filepath_to_healthcheck(v:val)') + end endfor return healthchecks endfunction - -" Extracts 'foo' from 'health#foo#check'. -function! s:to_plugin_name(fn_name) abort - return substitute(a:fn_name, - \ '\v.*health\#(.+)\#check.*', '\1', '') -endfunction diff --git a/runtime/autoload/health/lsp.vim b/runtime/autoload/health/lsp.vim deleted file mode 100644 index 2d2ba91cdf..0000000000 --- a/runtime/autoload/health/lsp.vim +++ /dev/null @@ -1,5 +0,0 @@ -function! health#lsp#check() abort - call health#report_start('Checking language server client configuration') - lua require 'vim.lsp.health'.check_health() -endfunction - diff --git a/runtime/autoload/health/treesitter.vim b/runtime/autoload/health/treesitter.vim deleted file mode 100644 index 5f167310ce..0000000000 --- a/runtime/autoload/health/treesitter.vim +++ /dev/null @@ -1,5 +0,0 @@ -function! health#treesitter#check() abort - call health#report_start('Checking treesitter configuration') - lua require 'vim.treesitter.health'.check_health() -endfunction - diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim index b6edc4c4d8..ef0282848f 100644 --- a/runtime/autoload/netrw.vim +++ b/runtime/autoload/netrw.vim @@ -1711,7 +1711,8 @@ fun! s:NetrwOptionsSafe(islocal) if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif setl fo=nroql2 - call s:NetrwSetSafeSetting("&go","begmr") + " call s:NetrwSetSafeSetting("&go","begmr") + if &go =~ '\ca' | call s:NetrwSetSafeSetting("&go",substitute(&go,'\ca','','g')) | endif call s:NetrwSetSafeSetting("&l:hid",0) call s:NetrwSetSafeSetting("&l:im",0) setl isk+=@ isk+=* isk+=/ diff --git a/runtime/autoload/provider/pythonx.vim b/runtime/autoload/provider/pythonx.vim index c292b374b6..0eeb35cba8 100644 --- a/runtime/autoload/provider/pythonx.vim +++ b/runtime/autoload/provider/pythonx.vim @@ -96,7 +96,7 @@ function! provider#pythonx#CheckForModule(prog, module, major_version) abort if prog_version !~ '^' . a:major_version return [0, prog_path . ' is Python ' . prog_version . ' and cannot provide Python ' \ . a:major_version . '.'] - elseif prog_version =~ '^' . a:major_version && prog_version < min_version + elseif prog_version =~ '^' . a:major_version && str2nr(prog_version[2:]) < str2nr(min_version[2:]) return [0, prog_path . ' is Python ' . prog_version . ' and cannot provide Python >= ' \ . min_version . '.'] endif |