_deprecated.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.lang = {}
  49. setmetatable(lvim.lang, mt)
  50. end
  51. function M.post_load()
  52. if lvim.lsp.override and not vim.tbl_isempty(lvim.lsp.override) then
  53. deprecate("lvim.lsp.override", "Use `lvim.lsp.automatic_configuration.skipped_servers` instead")
  54. vim.tbl_map(function(c)
  55. if not vim.tbl_contains(lvim.lsp.automatic_configuration.skipped_servers, c) then
  56. table.insert(lvim.lsp.automatic_configuration.skipped_servers, c)
  57. end
  58. end, lvim.lsp.override)
  59. end
  60. if lvim.autocommands.custom_groups then
  61. deprecate(
  62. "lvim.autocommands.custom_groups",
  63. "Use vim.api.nvim_create_autocmd instead or check LunarVim#2592 to learn about the new syntax"
  64. )
  65. end
  66. if lvim.lsp.automatic_servers_installation then
  67. deprecate(
  68. "lvim.lsp.automatic_servers_installation",
  69. "Use `lvim.lsp.installer.setup.automatic_installation` instead"
  70. )
  71. end
  72. local function convert_spec_to_lazy(spec)
  73. local alternatives = {
  74. setup = "init",
  75. as = "name",
  76. opt = "lazy",
  77. run = "build",
  78. lock = "pin",
  79. tag = "version",
  80. }
  81. alternatives.requires = function()
  82. if type(spec.requires) == "string" then
  83. spec.dependencies = { spec.requires }
  84. else
  85. spec.dependencies = spec.requires
  86. end
  87. return "Use `dependencies` instead"
  88. end
  89. alternatives.disable = function()
  90. if type(spec.disabled) == "function" then
  91. spec.enabled = function()
  92. return not spec.disabled()
  93. end
  94. else
  95. spec.enabled = not spec.disabled
  96. end
  97. return "Use `enabled` instead"
  98. end
  99. alternatives.wants = function()
  100. return "It's not needed in most cases, otherwise use `dependencies`."
  101. end
  102. alternatives.needs = alternatives.wants
  103. alternatives.module = function()
  104. spec.lazy = true
  105. return "Use `lazy = true` instead."
  106. end
  107. for old_key, alternative in pairs(alternatives) do
  108. if spec[old_key] ~= nil then
  109. local message
  110. if type(alternative) == "function" then
  111. message = alternative()
  112. else
  113. spec[alternative] = spec[old_key]
  114. end
  115. spec[old_key] = nil
  116. message = message or string.format("Use `%s` instead.", alternative)
  117. deprecate(
  118. string.format("%s` in `lvim.plugins", old_key),
  119. message .. " See https://github.com/folke/lazy.nvim#-migration-guide"
  120. )
  121. end
  122. end
  123. if spec[1] and spec[1]:match "^http" then
  124. spec.url = spec[1]
  125. spec[1] = nil
  126. deprecate("{ 'http...' }` in `lvim.plugins", "Use { url = 'http...' } instead.")
  127. end
  128. end
  129. for _, plugin in ipairs(lvim.plugins) do
  130. if type(plugin) == "table" then
  131. convert_spec_to_lazy(plugin)
  132. end
  133. end
  134. if lvim.builtin.terminal.execs then
  135. deprecate(
  136. "lvim.builtin.terminal.execs",
  137. "Use `lvim.builtin.terminal.terminals` instead. See https://www.lunarvim.org/docs/configuration/keybindings#toggleterm-terminal-mappings"
  138. )
  139. for _, v in ipairs(lvim.builtin.terminal.execs) do
  140. local keybind = {
  141. cmd = v[1],
  142. keymap = v[2],
  143. desc = v[3],
  144. direction = v[4],
  145. size = v[5],
  146. }
  147. lvim.builtin.terminal.terminals[#lvim.builtin.terminal.terminals + 1] = keybind
  148. end
  149. end
  150. end
  151. return M