aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/shared.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-10-17 17:57:14 +0200
committerJustin M. Keyes <justinkz@gmail.com>2024-10-21 00:54:42 +0200
commitc9c17fda80d843158d2785b047fca3a6dd78ea2f (patch)
tree2b1eff28539fbeff9ed8528b865543d40093df0e /runtime/lua/vim/shared.lua
parent0083e03d6fa7586d0d6360b40b52b0cab0d2e7ba (diff)
downloadrneovim-c9c17fda80d843158d2785b047fca3a6dd78ea2f.tar.gz
rneovim-c9c17fda80d843158d2785b047fca3a6dd78ea2f.tar.bz2
rneovim-c9c17fda80d843158d2785b047fca3a6dd78ea2f.zip
feat(deprecations): vim._defer_deprecated_module()
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r--runtime/lua/vim/shared.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index d11489b539..fd6a37001d 100644
--- a/runtime/lua/vim/shared.lua
+++ b/runtime/lua/vim/shared.lua
@@ -1164,6 +1164,32 @@ function vim._defer_require(root, mod)
})
end
+--- @private
+--- Creates a module alias/shim that lazy-loads a target module.
+---
+--- Unlike `vim.defaulttable()` this also:
+--- - implements __call
+--- - calls vim.deprecate()
+---
+--- @param old_name string Name of the deprecated module, which will be shimmed.
+--- @param new_name string Name of the new module, which will be loaded by require().
+function vim._defer_deprecated_module(old_name, new_name)
+ return setmetatable({}, {
+ ---@param _ table<string, any>
+ ---@param k string
+ __index = function(_, k)
+ vim.deprecate(old_name, new_name, '2.0.0', nil, false)
+ local target = require(new_name)
+ return target[k]
+ end,
+ __call = function(self)
+ vim.deprecate(old_name, new_name, '2.0.0', nil, false)
+ local target = require(new_name)
+ return target(self)
+ end,
+ })
+end
+
--- @nodoc
--- @class vim.context.mods
--- @field bo? table<string, any>