mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-16 11:00:23 +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 display? (fun(list_item: HarpoonListItem): string)
|
||||||
---@field select? (fun(list_item?: HarpoonListItem, list: HarpoonList, options: any?): nil)
|
---@field select? (fun(list_item?: HarpoonListItem, list: HarpoonList, options: any?): nil)
|
||||||
---@field equals? (fun(list_line_a: HarpoonListItem, list_line_b: HarpoonListItem): boolean)
|
---@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 BufLeave? fun(evt: any, list: HarpoonList): nil
|
||||||
---@field VimLeavePre? fun(evt: any, list: HarpoonList): nil
|
---@field VimLeavePre? fun(evt: any, list: HarpoonList): nil
|
||||||
---@field get_root_dir? fun(): string
|
---@field get_root_dir? fun(): string
|
||||||
@ -149,7 +149,7 @@ function M.get_default_config()
|
|||||||
---@param config HarpoonPartialConfigItem
|
---@param config HarpoonPartialConfigItem
|
||||||
---@param name? any
|
---@param name? any
|
||||||
---@return HarpoonListItem
|
---@return HarpoonListItem
|
||||||
add = function(config, name)
|
create_list_item = function(config, name)
|
||||||
name = name
|
name = name
|
||||||
-- TODO: should we do path normalization???
|
-- TODO: should we do path normalization???
|
||||||
-- i know i have seen sometimes it becoming an absolute
|
-- i know i have seen sometimes it becoming an absolute
|
||||||
@ -163,7 +163,7 @@ function M.get_default_config()
|
|||||||
config.get_root_dir()
|
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)
|
local bufnr = vim.fn.bufnr(name, false)
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
local Logger = require("harpoon.logger")
|
||||||
local Listeners = require("harpoon.listeners")
|
local Listeners = require("harpoon.listeners")
|
||||||
|
|
||||||
local function index_of(items, element, config)
|
local function index_of(items, element, config)
|
||||||
@ -48,9 +49,10 @@ end
|
|||||||
|
|
||||||
---@return HarpoonList
|
---@return HarpoonList
|
||||||
function HarpoonList:append(item)
|
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)
|
local index = index_of(self.items, item, self.config)
|
||||||
|
Logger:log("HarpoonList:append", { item = item, index = index })
|
||||||
if index == -1 then
|
if index == -1 then
|
||||||
Listeners.listeners:emit(
|
Listeners.listeners:emit(
|
||||||
Listeners.event_names.ADD,
|
Listeners.event_names.ADD,
|
||||||
@ -64,8 +66,9 @@ end
|
|||||||
|
|
||||||
---@return HarpoonList
|
---@return HarpoonList
|
||||||
function HarpoonList:prepend(item)
|
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)
|
local index = index_of(self.items, item, self.config)
|
||||||
|
Logger:log("HarpoonList:prepend", { item = item, index = index })
|
||||||
if index == -1 then
|
if index == -1 then
|
||||||
Listeners.listeners:emit(
|
Listeners.listeners:emit(
|
||||||
Listeners.event_names.ADD,
|
Listeners.event_names.ADD,
|
||||||
@ -79,13 +82,14 @@ end
|
|||||||
|
|
||||||
---@return HarpoonList
|
---@return HarpoonList
|
||||||
function HarpoonList:remove(item)
|
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
|
for i, v in ipairs(self.items) do
|
||||||
if self.config.equals(v, item) then
|
if self.config.equals(v, item) then
|
||||||
Listeners.listeners:emit(
|
Listeners.listeners:emit(
|
||||||
Listeners.event_names.REMOVE,
|
Listeners.event_names.REMOVE,
|
||||||
{ list = self, item = item, idx = i }
|
{ list = self, item = item, idx = i }
|
||||||
)
|
)
|
||||||
|
Logger:log("HarpoonList:remove", { item = item, index = i })
|
||||||
table.remove(self.items, i)
|
table.remove(self.items, i)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -99,6 +103,7 @@ function HarpoonList:removeAt(index)
|
|||||||
Listeners.event_names.REMOVE,
|
Listeners.event_names.REMOVE,
|
||||||
{ list = self, item = self.items[index], idx = index }
|
{ list = self, item = self.items[index], idx = index }
|
||||||
)
|
)
|
||||||
|
Logger:log("HarpoonList:removeAt", { item = self.items[index], index = index })
|
||||||
table.remove(self.items, index)
|
table.remove(self.items, index)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@ -140,7 +145,7 @@ function HarpoonList:resolve_displayed(displayed)
|
|||||||
Listeners.event_names.ADD,
|
Listeners.event_names.ADD,
|
||||||
{ list = self, item = v, idx = i }
|
{ 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
|
else
|
||||||
local index_in_new_list =
|
local index_in_new_list =
|
||||||
index_of(new_list, self.items[index], self.config)
|
index_of(new_list, self.items[index], self.config)
|
||||||
|
@ -2,7 +2,7 @@ local Config = require("harpoon.config")
|
|||||||
local eq = assert.are.same
|
local eq = assert.are.same
|
||||||
|
|
||||||
describe("config", function()
|
describe("config", function()
|
||||||
it("default.add", function()
|
it("default.create_list_item", function()
|
||||||
local config = Config.get_default_config()
|
local config = Config.get_default_config()
|
||||||
local config_item = Config.get_config(config, "foo")
|
local config_item = Config.get_config(config, "foo")
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ describe("config", function()
|
|||||||
})
|
})
|
||||||
vim.api.nvim_win_set_cursor(0, { 3, 1 })
|
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, {
|
eq(item, {
|
||||||
value = "/tmp/harpoon-test",
|
value = "/tmp/harpoon-test",
|
||||||
context = {
|
context = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user