diff --git a/lua/harpoon/config.lua b/lua/harpoon/config.lua index 3feac15..260f004 100644 --- a/lua/harpoon/config.lua +++ b/lua/harpoon/config.lua @@ -19,7 +19,7 @@ M.DEFAULT_LIST = DEFAULT_LIST ---@field display? (fun(list_item: HarpoonListItem): string) ---@field select? (fun(list_item?: HarpoonListItem, list: HarpoonList, options: any?): nil) ---@field equals? (fun(list_line_a: HarpoonListItem, list_line_b: HarpoonListItem): boolean) ----@field add? fun(config: HarpoonPartialConfigItem, item: any?): HarpoonListItem +---@field create_list_item? fun(config: HarpoonPartialConfigItem, item: any?): HarpoonListItem ---@field BufLeave? fun(evt: any, list: HarpoonList): nil ---@field VimLeavePre? fun(evt: any, list: HarpoonList): nil ---@field get_root_dir? fun(): string @@ -149,7 +149,7 @@ function M.get_default_config() ---@param config HarpoonPartialConfigItem ---@param name? any ---@return HarpoonListItem - add = function(config, name) + create_list_item = function(config, name) name = name -- TODO: should we do path normalization??? -- i know i have seen sometimes it becoming an absolute @@ -163,7 +163,7 @@ function M.get_default_config() config.get_root_dir() ) - Logger:log("config_default#add", name) + Logger:log("config_default#create_list_item", name) local bufnr = vim.fn.bufnr(name, false) diff --git a/lua/harpoon/list.lua b/lua/harpoon/list.lua index 52588d9..20a44e3 100644 --- a/lua/harpoon/list.lua +++ b/lua/harpoon/list.lua @@ -1,3 +1,4 @@ +local Logger = require("harpoon.logger") local Listeners = require("harpoon.listeners") local function index_of(items, element, config) @@ -48,9 +49,10 @@ end ---@return HarpoonList function HarpoonList:append(item) - item = item or self.config.add(self.config) + item = item or self.config.create_list_item(self.config) local index = index_of(self.items, item, self.config) + Logger:log("HarpoonList:append", { item = item, index = index }) if index == -1 then Listeners.listeners:emit( Listeners.event_names.ADD, @@ -64,8 +66,9 @@ end ---@return HarpoonList function HarpoonList:prepend(item) - item = item or self.config.add(self.config) + item = item or self.config.create_list_item(self.config) local index = index_of(self.items, item, self.config) + Logger:log("HarpoonList:prepend", { item = item, index = index }) if index == -1 then Listeners.listeners:emit( Listeners.event_names.ADD, @@ -79,13 +82,14 @@ end ---@return HarpoonList function HarpoonList:remove(item) - item = item or self.config.add(self.config) + item = item or self.config.create_list_item(self.config) for i, v in ipairs(self.items) do if self.config.equals(v, item) then Listeners.listeners:emit( Listeners.event_names.REMOVE, { list = self, item = item, idx = i } ) + Logger:log("HarpoonList:remove", { item = item, index = i }) table.remove(self.items, i) break end @@ -99,6 +103,7 @@ function HarpoonList:removeAt(index) Listeners.event_names.REMOVE, { list = self, item = self.items[index], idx = index } ) + Logger:log("HarpoonList:removeAt", { item = self.items[index], index = index }) table.remove(self.items, index) return self end @@ -140,7 +145,7 @@ function HarpoonList:resolve_displayed(displayed) Listeners.event_names.ADD, { list = self, item = v, idx = i } ) - new_list[i] = self.config.add(self.config, v) + new_list[i] = self.config.create_list_item(self.config, v) else local index_in_new_list = index_of(new_list, self.items[index], self.config) diff --git a/lua/harpoon/test/config_spec.lua b/lua/harpoon/test/config_spec.lua index d22555a..227b1eb 100644 --- a/lua/harpoon/test/config_spec.lua +++ b/lua/harpoon/test/config_spec.lua @@ -2,7 +2,7 @@ local Config = require("harpoon.config") local eq = assert.are.same describe("config", function() - it("default.add", function() + it("default.create_list_item", function() local config = Config.get_default_config() local config_item = Config.get_config(config, "foo") @@ -17,7 +17,7 @@ describe("config", function() }) vim.api.nvim_win_set_cursor(0, { 3, 1 }) - local item = config_item.add(config_item) + local item = config_item.create_list_item(config_item) eq(item, { value = "/tmp/harpoon-test", context = {