neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

health.lua (1290B)


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