mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
feat: logging and rename.
This commit is contained in:
parent
c24c7119a2
commit
e9d18fca95
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user