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,3 +1,15 @@
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
local findCmd = "" local findCmd = ""
--- @class Set A simple Set implementation using a table to avoid duplicates; it only contains the methods add and toList --- @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. --- @field _data table<string, 1> Table to hold the set data.
@ -17,29 +29,6 @@ function supportedFiletypeSet:toList()
return vim.tbl_keys(self._data) return vim.tbl_keys(self._data)
end 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
end
local function disableWithWarnMessage(msg) local function disableWithWarnMessage(msg)
LazyVim.warn( LazyVim.warn(
"You have enabled extras.editor.medias, see (:`LazyExtras`). \n\n" "You have enabled extras.editor.medias, see (:`LazyExtras`). \n\n"
@ -98,10 +87,25 @@ return {
end end
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 return true
end, end,
keys = { keys = {
{ "<leader>fP", "<cmd>Telescope media_files<cr>", desc = "Find Media Files" }, { "<leader>fP", "<cmd>Telescope media_files<cr>", desc = "Find Media Files" },
}, },
}, },
},
},
} }