telescope.nvim
telescope.nvim copied to clipboard
load_extension calls setup() twice
Description
When I call require("telescope").load_extension "foo_bar", it seems extension's setup() is called twice. load_extension() is implemented like below in HEAD (2d92125).
- call
load_extension() - It calls
_extension.load()https://github.com/nvim-telescope/telescope.nvim/blob/2d92125620417fbea82ec30303823e3cd69e90e8/lua/telescope/init.lua#L143-L143 load()calls extension'ssetup()at the first time. https://github.com/nvim-telescope/telescope.nvim/blob/2d92125620417fbea82ec30303823e3cd69e90e8/lua/telescope/_extensions/init.lua#L62-L65- Then it access to
manager. https://github.com/nvim-telescope/telescope.nvim/blob/2d92125620417fbea82ec30303823e3cd69e90e8/lua/telescope/_extensions/init.lua#L66-L66 managerhas a metatable, and it callssetup()again by__indexentry. https://github.com/nvim-telescope/telescope.nvim/blob/2d92125620417fbea82ec30303823e3cd69e90e8/lua/telescope/_extensions/init.lua#L17-L21
Neovim version
NVIM v0.10.0-dev-3454+gb263c73b0-Homebrew
Build type: Release
LuaJIT 2.1.0-beta3
Operating system and version
macOS 13.4.1
Telescope version / branch / rev
2d92125
checkhealth telescope
==============================================================================
telescope: require("telescope.health").check()
Checking for required plugins ~
- OK plenary installed.
- OK nvim-treesitter installed.
Checking external dependencies ~
- OK rg: found ripgrep 13.0.0
- OK fd: found fd 8.7.0
Steps to reproduce
nvim -nu minimal.lua:Telescope frecency
Expected behavior
extension's setup() should be called once.
Actual behavior
extension's setup() is called twice.
Minimal config
-- clone required modules on cwd
vim.opt.runtimepath:append("plenary.nvim")
vim.opt.runtimepath:append("telescope.nvim")
vim.opt.runtimepath:append("telescope-frecency.nvim")
vim.opt.runtimepath:append("sqlite.lua")
local telescope = require("telescope")
telescope.setup({ extensions = { frecency = { db_root = vim.uv.cwd() } } })
telescope.load_extension("frecency")
relevant PR https://github.com/nvim-telescope/telescope.nvim/pull/1795
couldn't this not be resolved by just doing
extensions.load = function(name)
return extensions.manager[name]
end
that at least eliminates the case that load_extension calls setup twice in the same call stack and it still allows for lazy loading.