robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
1.4 KiB46 linesraw
1local M = {}
2local health = vim.health
3
4local deprecated = {} ---@type table<string, [string, string[], string?]>
5
6function 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_str, minor_str = version:match('(%d+)%.(%d+)')
17    local major, minor = vim._assert_integer(major_str), vim._assert_integer(minor_str)
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
28end
29
30--- @param name string
31--- @param version string
32--- @param backtrace string
33--- @param alternative? string
34function M.add(name, version, backtrace, alternative)
35  if deprecated[name] == nil then
36    deprecated[name] = { version, { backtrace }, alternative }
37    return
38  end
39
40  local it = vim.iter(deprecated[name][2])
41  if it:find(backtrace) == nil then
42    table.insert(deprecated[name][2], backtrace)
43  end
44end
45
46return M