AdeAttwood / ivy.nvim

An ivy-mode port to neovim.
35 stars 4 forks source link

Implement setup function #81

Closed AdeAttwood closed 4 months ago

AdeAttwood commented 4 months ago

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.

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.

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.

require('ivy').register_backend("ivy.backends.files")

As well as the register_backend the core runfunction is exposed. With this exposed we should be able to build anything we want.

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

Testing with a manual setup:

require('ivy').setup {
  backends = {
    "ivy.backends.buffers",
    "ivy.backends.files",
  },
}

Testing with Lazy:

require("lazy").setup({
  {
    "AdeAttwood/ivy.nvim",
    branch = "adeattwood/setup-function",
    build = "cargo build --release",
    config = {
      backends = {
        { "ivy.backends.files", { keymap = "<C-p>" } },
      },
    },
  },
})
AdeAttwood commented 4 months ago

@arnevm123 what do we think about getting this is now. I have bitten the bullet and gone full setup.

arnevm123 commented 4 months ago

Looks good!

Just a small question: running setup without any options now will return an error, for me it would make sense to have a default set of backends that are registered with this, similar to the behaviour of the application now?

Also, should the keymaps for the window be configurable? Most of them seem very intuitive and don't need changing for me, except for maybe next/ next checkpoint or the previous versions. But for me there's no need yet.