update plugin spec for avoid messup telescope lazy load

This commit is contained in:
arthur 2024-06-11 22:40:10 +08:00
parent 70efad4973
commit 793b2e4b1d

View file

@ -1,9 +1,21 @@
local findCmd = ""
--- @class Set A simple Set implementation using a table to avoid duplicates; it only contains the methods add and toList
--- @field _data table<string, 1> Table to hold the set data.
local supportedFiletypeSet = { _data = {} }
return {
{
"nvim-telescope/telescope.nvim",
optional = true,
dependencies = {
{
"nvim-telescope/telescope-media-files.nvim",
enabled = function()
if not vim.tbl_contains(LazyVim.config.json.data.extras, "lazyvim.plugins.extras.editor.medias") then
return false
end
function supportedFiletypeSet:add(values)
local findCmd = ""
--- @class Set A simple Set implementation using a table to avoid duplicates; it only contains the methods add and toList
--- @field _data table<string, 1> Table to hold the set data.
local supportedFiletypeSet = { _data = {} }
function supportedFiletypeSet:add(values)
values = type(values) == "string" and { values } or values
for _, value in ipairs(values) do
@ -11,33 +23,10 @@ function supportedFiletypeSet:add(values)
self._data[value] = 1
end
end
end
function supportedFiletypeSet:toList()
return vim.tbl_keys(self._data)
end
return {
{
"nvim-telescope/telescope-media-files.nvim",
dependencies = {
{
"nvim-telescope/telescope.nvim",
opts = function(_, opts)
opts.extensions = vim.tbl_extend("force", opts.extensions or {}, {
media_files = { filetypes = supportedFiletypeSet:toList(), find_cmd = findCmd },
})
return opts
end,
},
},
cond = function()
if not LazyVim.has("telescope.nvim") then
return false
end
if not vim.tbl_contains(LazyVim.config.json.data.extras, "lazyvim.plugins.extras.editor.medias") then
return false
function supportedFiletypeSet:toList()
return vim.tbl_keys(self._data)
end
local function disableWithWarnMessage(msg)
@ -98,10 +87,25 @@ return {
end
end
-- Setup extension for media files when telescope is loaded
LazyVim.on_load("telescope.nvim", function()
local ok, telescope = pcall(require, "telescope")
if ok then
telescope.extensions["media_files"] = vim.tbl_extend("force", telescope.extensions["media_files"] or {}, {
filetypes = supportedFiletypeSet:toList(),
find_cmd = findCmd,
})
else
LazyVim.error("Failed to load telescope.nvim")
end
end)
return true
end,
keys = {
{ "<leader>fP", "<cmd>Telescope media_files<cr>", desc = "Find Media Files" },
},
},
},
},
}