update: if the required prerequisites are not installed, we need an early return.

This commit is contained in:
arthur 2024-06-09 22:45:17 +08:00
parent 507973278c
commit 7c758fd69e

View file

@ -28,13 +28,13 @@ return {
}, },
} }
local errors = {}
local filetypes = {} local filetypes = {}
-- Ensure all required prerequisites are installed -- Ensure all required prerequisites are installed
for _, tool in ipairs(prerequisites.required) do for _, tool in ipairs(prerequisites.required) do
if vim.fn.executable(tool.cmd) == 0 then if vim.fn.executable(tool.cmd) == 0 then
table.insert(errors, "Required prerequisite not installed: " .. tool.name) LazyVim.error("Required prerequisite not installed: " .. tool.name)
return
else else
filetypes = vim.tbl_extend("force", filetypes, tool.filetypes) filetypes = vim.tbl_extend("force", filetypes, tool.filetypes)
end end
@ -50,7 +50,13 @@ return {
end end
if not findCmd then if not findCmd then
table.insert(errors, "None of the required 'find cmd' prerequisites are installed") LazyVim.error(
"None of the required 'find cmd' prerequisites is installed.\n"
.. "Please install at least one of the following: `rd`, `rg`, or `find`.\n"
.. "More information can be found at: "
.. "https://github.com/nvim-telescope/telescope-media-files.nvim?tab=readme-ov-file#prerequisites"
)
return
end end
-- Check optional prerequisites and include their filetypes if installed -- Check optional prerequisites and include their filetypes if installed
@ -60,12 +66,6 @@ return {
end end
end end
-- If one of required prerequisites not installed print them and return
if #errors > 0 then
LazyVim.error(table.concat(errors, "\n"))
return
end
-- Setup media_files extension for telescope -- Setup media_files extension for telescope
LazyVim.on_load("telescope.nvim", function() LazyVim.on_load("telescope.nvim", function()
local ok, err = pcall(require("telescope").load_extension, "media_files") local ok, err = pcall(require("telescope").load_extension, "media_files")