Summary:
Now when using ivy.nvim you will need to call the `setup` function. This will
need to register any backends you want to use. This is an example config, this
can be put into a plugin in `~/.config/nvim/plugin/ivy.lua` for example.
```lua
require('ivy').setup {
backends = {
"ivy.backends.buffers",
"ivy.backends.files",
},
}
```
If you are using Lazy you can use the `config` directly to call the setup
function.
```lua
return {
"AdeAttwood/ivy.nvim",
build = "cargo build --release",
config = {
backends = {
"ivy.backends.buffers",
"ivy.backends.files",
}
}
}
```
The `setup` function can only be called once, if its called a second time any
backends or config will not be used. The module does expose the
`register_backend` function, this can be used to load backends before or after
the setup function is called.
```lua
require('ivy').register_backend("ivy.backends.files")
```
As well as the `register_backend` the core `run`function is exposed. With this
exposed we should be able to build anything we want.
```lua
vim.ivy.run(
"Title",
function(input)
return {
{ content = "One" },
{ content = "Two" },
{ content = "Three" },
}
end,
function(result) vim.cmd("edit " .. result) end
)
```
Test Plan:
Not much to test in this one, it has been tested locally on my config that does
not use any plugin managers, also a sandbox Lazy env using `NVIM_APPNAME`
NVIM_APPNAME
28 lines
634 B
Lua
28 lines
634 B
Lua
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
|