feat: implement a setup function
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
This commit is contained in:
parent
eb71e6bcfa
commit
508cf47d5c
2 changed files with 28 additions and 12 deletions
28
lua/ivy/init.lua
Normal file
28
lua/ivy/init.lua
Normal file
|
|
@ -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
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
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`.
|
||||
|
|
@ -17,15 +16,4 @@ vim.paste = (function(overridden)
|
|||
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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue