_deprecated.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. ---@diagnostic disable: deprecated
  2. local M = {}
  3. local function deprecate(name, alternative)
  4. local in_headless = #vim.api.nvim_list_uis() == 0
  5. if in_headless then
  6. return
  7. end
  8. alternative = alternative or "See https://github.com/LunarVim/LunarVim#breaking-changes"
  9. local trace = debug.getinfo(3, "Sl")
  10. local shorter_src = trace.short_src
  11. local t = shorter_src .. ":" .. (trace.currentline or trace.lastlinedefined)
  12. vim.schedule(function()
  13. vim.notify_once(string.format("%s: `%s` is deprecated.\n %s.", t, name, alternative), vim.log.levels.WARN)
  14. end)
  15. end
  16. function M.handle()
  17. local mt = {
  18. __newindex = function(_, k, _)
  19. deprecate(k)
  20. end,
  21. }
  22. ---@deprecated
  23. lvim.builtin.notify = {}
  24. setmetatable(lvim.builtin.notify, {
  25. __newindex = function(_, k, _)
  26. deprecate("lvim.builtin.notify." .. k, "See LunarVim#3294")
  27. end,
  28. })
  29. ---@deprecated
  30. lvim.builtin.dashboard = {}
  31. setmetatable(lvim.builtin.dashboard, {
  32. __newindex = function(_, k, _)
  33. deprecate("lvim.builtin.dashboard." .. k, "Use `lvim.builtin.alpha` instead. See LunarVim#1906")
  34. end,
  35. })
  36. ---@deprecated
  37. lvim.lsp.popup_border = {}
  38. setmetatable(lvim.lsp.popup_border, mt)
  39. ---@deprecated
  40. lvim.lsp.float = {}
  41. setmetatable(lvim.lsp.float, {
  42. __newindex = function(_, k, _)
  43. deprecate("lvim.lsp.float." .. k, "Use options provided by the handler instead")
  44. end,
  45. })
  46. ---@deprecated
  47. lvim.lsp.diagnostics = {}
  48. setmetatable(lvim.lsp.diagnostics, {
  49. __newindex = function(table, k, v)
  50. deprecate("lvim.lsp.diagnostics." .. k, string.format("Use `vim.diagnostic.config({ %s = %s })` instead", k, v))
  51. rawset(table, k, v)
  52. end,
  53. })
  54. ---@deprecated
  55. lvim.lang = {}
  56. setmetatable(lvim.lang, mt)
  57. end
  58. function M.post_load()
  59. if lvim.lsp.diagnostics and not vim.tbl_isempty(lvim.lsp.diagnostics) then
  60. vim.diagnostic.config(lvim.lsp.diagnostics)
  61. end
  62. if lvim.lsp.override and not vim.tbl_isempty(lvim.lsp.override) then
  63. deprecate("lvim.lsp.override", "Use `lvim.lsp.automatic_configuration.skipped_servers` instead")
  64. vim.tbl_map(function(c)
  65. if not vim.tbl_contains(lvim.lsp.automatic_configuration.skipped_servers, c) then
  66. table.insert(lvim.lsp.automatic_configuration.skipped_servers, c)
  67. end
  68. end, lvim.lsp.override)
  69. end
  70. if lvim.autocommands.custom_groups then
  71. deprecate(
  72. "lvim.autocommands.custom_groups",
  73. "Use vim.api.nvim_create_autocmd instead or check LunarVim#2592 to learn about the new syntax"
  74. )
  75. end
  76. if lvim.lsp.automatic_servers_installation then
  77. deprecate(
  78. "lvim.lsp.automatic_servers_installation",
  79. "Use `lvim.lsp.installer.setup.automatic_installation` instead"
  80. )
  81. end
  82. local function convert_spec_to_lazy(spec)
  83. local alternatives = {
  84. setup = "init",
  85. as = "name",
  86. opt = "lazy",
  87. run = "build",
  88. lock = "pin",
  89. tag = "version",
  90. }
  91. alternatives.requires = function()
  92. if type(spec.requires) == "string" then
  93. spec.dependencies = { spec.requires }
  94. else
  95. spec.dependencies = spec.requires
  96. end
  97. return "Use `dependencies` instead"
  98. end
  99. alternatives.disable = function()
  100. if type(spec.disabled) == "function" then
  101. spec.enabled = function()
  102. return not spec.disabled()
  103. end
  104. else
  105. spec.enabled = not spec.disabled
  106. end
  107. return "Use `enabled` instead"
  108. end
  109. alternatives.wants = function()
  110. return "It's not needed in most cases, otherwise use `dependencies`."
  111. end
  112. alternatives.needs = alternatives.wants
  113. alternatives.module = function()
  114. spec.lazy = true
  115. return "Use `lazy = true` instead."
  116. end
  117. for old_key, alternative in pairs(alternatives) do
  118. if spec[old_key] ~= nil then
  119. local message
  120. if type(alternative) == "function" then
  121. message = alternative()
  122. else
  123. spec[alternative] = spec[old_key]
  124. end
  125. spec[old_key] = nil
  126. message = message or string.format("Use `%s` instead.", alternative)
  127. deprecate(
  128. string.format("%s` in `lvim.plugins", old_key),
  129. message .. " See https://github.com/folke/lazy.nvim#-migration-guide"
  130. )
  131. end
  132. end
  133. if spec[1] and spec[1]:match "^http" then
  134. spec.url = spec[1]
  135. spec[1] = nil
  136. deprecate("{ 'http...' }` in `lvim.plugins", "Use { url = 'http...' } instead.")
  137. end
  138. end
  139. for _, plugin in ipairs(lvim.plugins) do
  140. if type(plugin) == "table" then
  141. convert_spec_to_lazy(plugin)
  142. end
  143. end
  144. end
  145. return M