From ded926a4a6997c1a725206d91129bf922bd3c474 Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Tue, 3 Sep 2024 19:34:17 +0100 Subject: [PATCH] chore: make public api consistent Summary: Right now we have two ways to access the public api we have `require('ivy')` and `vim.ivy. Each way has a different api that will cause some confusion. Now both apis are the same so anyone that wants to integrate with ivy can do so without having to figure out what one they need to use. Test Plan: The unit tests cover most of the work, I have also been using this locally for quite some time now with now issues. --- lua/ivy/controller.lua | 3 +-- lua/ivy/init.lua | 17 +++++++++++++++++ plugin/ivy.lua | 4 ++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lua/ivy/controller.lua b/lua/ivy/controller.lua index 6f0caa4..fc2c726 100644 --- a/lua/ivy/controller.lua +++ b/lua/ivy/controller.lua @@ -3,7 +3,6 @@ local prompt = require "ivy.prompt" local utils = require "ivy.utils" local controller = {} -controller.action = utils.actions controller.items = nil controller.callback = nil @@ -56,7 +55,7 @@ end controller.checkpoint = function() vim.api.nvim_set_current_win(window.origin) - controller.callback(window.get_current_selection(), controller.action.CHECKPOINT) + controller.callback(window.get_current_selection(), utils.actions.CHECKPOINT) vim.api.nvim_set_current_win(window.window) end diff --git a/lua/ivy/init.lua b/lua/ivy/init.lua index 58672ff..933ce36 100644 --- a/lua/ivy/init.lua +++ b/lua/ivy/init.lua @@ -1,11 +1,28 @@ local controller = require "ivy.controller" +local libivy = require "ivy.libivy" local config = require "ivy.config" +local utils = require "ivy.utils" local register_backend = require "ivy.register_backend" local ivy = {} + +ivy.action = utils.actions +ivy.utils = utils + +ivy.match = libivy.ivy_match + ivy.run = controller.run ivy.register_backend = register_backend +ivy.checkpoint = controller.checkpoint +ivy.paste = controller.paste +ivy.complete = controller.complete +ivy.destroy = controller.destroy +ivy.input = controller.input +ivy.next = controller.next +ivy.previous = controller.previous +ivy.search = controller.search + -- Private variable to check if ivy has been setup, this is to prevent multiple -- setups of ivy. This is only exposed for testing purposes. ---@private diff --git a/plugin/ivy.lua b/plugin/ivy.lua index cab4b9a..f57ebd4 100644 --- a/plugin/ivy.lua +++ b/plugin/ivy.lua @@ -1,9 +1,9 @@ -local controller = require "ivy.controller" +local api = require "ivy" -- 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.ivy = api vim.paste = (function(overridden) return function(lines, phase)