_deprecated.lua 4.8 KB

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