_deprecated.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. requires = "dependencies",
  98. }
  99. alternatives.tag = function()
  100. if spec.tag == "*" then
  101. spec.version = "*"
  102. return [[version = "*"]]
  103. end
  104. end
  105. alternatives.disable = function()
  106. if type(spec.disabled) == "function" then
  107. spec.enabled = function()
  108. return not spec.disabled()
  109. end
  110. else
  111. spec.enabled = not spec.disabled
  112. end
  113. return "enabled = " .. vim.inspect(spec.enabled)
  114. end
  115. alternatives.wants = function()
  116. return "dependencies = [value]"
  117. end
  118. alternatives.needs = alternatives.wants
  119. alternatives.module = function()
  120. spec.lazy = true
  121. return "lazy = true"
  122. end
  123. for old_key, alternative in pairs(alternatives) do
  124. if spec[old_key] ~= nil then
  125. local message
  126. local old_value = vim.inspect(spec[old_key]) or "value"
  127. if type(alternative) == "function" then
  128. message = alternative()
  129. else
  130. spec[alternative] = spec[old_key]
  131. end
  132. -- not every function in alternatives returns a message (e.g. tag)
  133. if type(alternative) ~= "function" or message then
  134. spec[old_key] = nil
  135. local new_value = vim.inspect(spec[alternative] or "[value]")
  136. message = message or string.format("%s = %s", alternative, new_value)
  137. vim.schedule(function()
  138. vim.notify_once(
  139. string.format(
  140. [[`%s = %s` in `lvim.plugins` has been deprecated since the migration to lazy.nvim. Use `%s` instead.
  141. Example:
  142. `lvim.plugins = {... {... %s = %s ...} ...}`
  143. ->
  144. `lvim.plugins = {... {... %s ...} ...}`
  145. See https://github.com/folke/lazy.nvim#-migration-guide"]],
  146. old_key,
  147. old_value,
  148. message,
  149. old_key,
  150. old_value,
  151. message
  152. ),
  153. vim.log.levels.WARN
  154. )
  155. end)
  156. end
  157. end
  158. end
  159. if spec[1] and spec[1]:match "^http" then
  160. spec.url = spec[1]
  161. spec[1] = nil
  162. vim.schedule(function()
  163. vim.notify_once(
  164. string.format(
  165. [[`"http..."` in `lvim.plugins` has been deprecated since the migration to lazy.nvim. Use `url = "http..."` instead.
  166. Example:
  167. `lvim.plugins = {... { "%s" ...} ...}`
  168. ->
  169. `lvim.plugins = {... { url = "%s" ...} ...}`
  170. See https://github.com/folke/lazy.nvim#-migration-guide"]],
  171. spec.url,
  172. spec.url
  173. ),
  174. vim.log.levels.WARN
  175. )
  176. end)
  177. end
  178. end
  179. for _, plugin in ipairs(lvim.plugins) do
  180. if type(plugin) == "table" then
  181. convert_spec_to_lazy(plugin)
  182. end
  183. end
  184. end
  185. return M