nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.43k stars 824 forks source link

load_extension calls setup() twice #2659

Open delphinus opened 1 year ago

delphinus commented 1 year ago

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).

  1. call load_extension()
  2. It calls _extension.load() https://github.com/nvim-telescope/telescope.nvim/blob/2d92125620417fbea82ec30303823e3cd69e90e8/lua/telescope/init.lua#L143-L143
  3. load() calls extension's setup() at the first time. https://github.com/nvim-telescope/telescope.nvim/blob/2d92125620417fbea82ec30303823e3cd69e90e8/lua/telescope/_extensions/init.lua#L62-L65
  4. Then it access to manager. https://github.com/nvim-telescope/telescope.nvim/blob/2d92125620417fbea82ec30303823e3cd69e90e8/lua/telescope/_extensions/init.lua#L66-L66
  5. manager has a metatable, and it calls setup() again by __index entry. 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

  1. nvim -nu minimal.lua
  2. :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")
jamestrew commented 1 year ago

relevant PR https://github.com/nvim-telescope/telescope.nvim/pull/1795

Conni2461 commented 11 months ago

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.