health.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. local M = {}
  2. local health = vim.health
  3. local deprecated = {} ---@type [string, table, string][]
  4. function M.check()
  5. if next(deprecated) == nil then
  6. health.ok('No deprecated functions detected')
  7. return
  8. end
  9. for name, v in vim.spairs(deprecated) do
  10. health.start('')
  11. local version, backtraces, alternative = v[1], v[2], v[3]
  12. local major, minor = version:match('(%d+)%.(%d+)')
  13. major, minor = tonumber(major), tonumber(minor)
  14. local removal_version = string.format('nvim-%d.%d', major, minor)
  15. local will_be_removed = vim.fn.has(removal_version) == 1 and 'was removed' or 'will be removed'
  16. local msg = ('%s is deprecated. Feature %s in Nvim %s'):format(name, will_be_removed, version)
  17. local msg_alternative = alternative and ('use %s instead.'):format(alternative)
  18. local advice = { msg_alternative }
  19. table.insert(advice, backtraces)
  20. advice = vim.iter(advice):flatten():totable()
  21. health.warn(msg, advice)
  22. end
  23. end
  24. function M.add(name, version, backtrace, alternative)
  25. if deprecated[name] == nil then
  26. deprecated[name] = { version, { backtrace }, alternative }
  27. return
  28. end
  29. local it = vim.iter(deprecated[name][2])
  30. if it:find(backtrace) == nil then
  31. table.insert(deprecated[name][2], backtrace)
  32. end
  33. end
  34. return M