health.lua 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. local M = {}
  2. function M.report_start(msg)
  3. vim.fn['health#report_start'](msg)
  4. end
  5. function M.report_info(msg)
  6. vim.fn['health#report_info'](msg)
  7. end
  8. function M.report_ok(msg)
  9. vim.fn['health#report_ok'](msg)
  10. end
  11. function M.report_warn(msg, ...)
  12. vim.fn['health#report_warn'](msg, ...)
  13. end
  14. function M.report_error(msg, ...)
  15. vim.fn['health#report_error'](msg, ...)
  16. end
  17. local path2name = function(path)
  18. if path:match('%.lua$') then
  19. -- Lua: transform "../lua/vim/lsp/health.lua" into "vim.lsp"
  20. return path:gsub('.-lua[%\\%/]', '', 1):gsub('[%\\%/]', '.'):gsub('%.health.-$', '')
  21. else
  22. -- Vim: transform "../autoload/health/provider.vim" into "provider"
  23. return vim.fn.fnamemodify(path, ':t:r')
  24. end
  25. end
  26. local PATTERNS = { '/autoload/health/*.vim', '/lua/**/**/health.lua', '/lua/**/**/health/init.lua' }
  27. -- :checkhealth completion function used by ex_getln.c get_healthcheck_names()
  28. M._complete = function()
  29. local names = vim.tbl_flatten(vim.tbl_map(function(pattern)
  30. return vim.tbl_map(path2name, vim.api.nvim_get_runtime_file(pattern, true))
  31. end, PATTERNS))
  32. -- Remove duplicates
  33. local unique = {}
  34. vim.tbl_map(function(f)
  35. unique[f] = true
  36. end, names)
  37. -- vim.health is this file, which is not a healthcheck
  38. unique['vim'] = nil
  39. return vim.tbl_keys(unique)
  40. end
  41. return M