Files
telescope.nvim/lua/telescope/_extensions/init.lua
Luke Kershaw 9aaaa0c5f3 fix: builtin only have entries for extension functions (#1587)
* fix: `builtin` only have entries for extension functions

* fix: add check for underscore and explanation of which functions included
2021-12-19 17:55:50 +00:00

68 lines
2.0 KiB
Lua

local extensions = {}
extensions._loaded = {}
extensions._config = {}
extensions._health = {}
extensions.manager = setmetatable({}, {
__index = function(t, k)
-- See if this extension exists.
local ok, ext = pcall(require, "telescope._extensions." .. k)
if not ok then
error("This extension doesn't exist or is not installed: " .. k .. "\n" .. ext)
end
if ext.setup then
ext.setup(extensions._config[k] or {}, require("telescope.config").values)
end
t[k] = ext.exports or {}
extensions._health[k] = ext.health
return t[k]
end,
})
--- Register an extension module.
---
--- Extensions have several important keys.
--- - setup:
--- function(ext_config, config) -> nil
---
--- Called when first loading the extension.
--- The first parameter is the config passed by the user
--- in telescope setup. The second parameter is the resulting
--- config.values after applying the users setup defaults.
---
--- It is acceptable for a plugin to override values in config,
--- as some plugins will be installed simply to manage some setup,
--- install some sorter, etc.
---
--- - exports:
--- table
---
--- Only the items in `exports` will be exposed on the resulting
--- module that users can access via require('telescope').extensions.foo
--- Also, any top-level key-value pairs in exports where the value is a function and the
--- key doesn't start with an underscore will be included when calling the `builtin` picker
--- with the `include_extensions` option enabled.
---
--- Other things in the module will not be accessible. This is the public API
--- for your extension. Consider not breaking it a lot :laugh:
---
--- TODO:
--- - actions
extensions.register = function(mod)
return mod
end
extensions.load = function(name)
return extensions.manager[name]
end
extensions.set_config = function(extensions_config)
extensions._config = extensions_config or {}
end
return extensions