diff --git a/lua/ivy/init.lua b/lua/ivy/init.lua new file mode 100644 index 0000000..f62f6fc --- /dev/null +++ b/lua/ivy/init.lua @@ -0,0 +1,28 @@ +local controller = require "ivy.controller" +local register_backend = require "ivy.register_backend" + +-- Local variable to check if ivy has been setup, this is to prevent multiple +-- setups of ivy +local has_setup = false + +local ivy = {} +ivy.run = controller.run +ivy.register_backend = register_backend + +---@class IvySetupOptions +---@field backends (IvyBackend | { ["1"]: string, ["2"]: IvyBackendOptions} | string)[] + +---@param config IvySetupOptions +function ivy.setup(config) + if has_setup then + return + end + + for _, backend in ipairs(config.backends) do + register_backend(backend) + end + + has_setup = true +end + +return ivy diff --git a/plugin/ivy.lua b/plugin/ivy.lua index 81169f9..cab4b9a 100644 --- a/plugin/ivy.lua +++ b/plugin/ivy.lua @@ -1,31 +1,19 @@ local controller = require "ivy.controller" -local register_backend = require "ivy.register_backend" -- Put the controller in to the vim global so we can access it in mappings -- better without requires. You can call controller commands like `vim.ivy.xxx`. -- luacheck: ignore vim.ivy = controller vim.paste = (function(overridden) return function(lines, phase) local file_type = vim.api.nvim_buf_get_option(0, "filetype") if file_type == "ivy" then vim.ivy.paste() else overridden(lines, phase) end end end)(vim.paste) -register_backend "ivy.backends.buffers" -register_backend "ivy.backends.files" -register_backend "ivy.backends.lines" -register_backend "ivy.backends.lsp-workspace-symbols" - -if vim.fn.executable "rg" then - register_backend "ivy.backends.rg" -elseif vim.fn.executable "ag" then - register_backend "ivy.backends.ag" -end - vim.cmd "highlight IvyMatch cterm=bold gui=bold"