mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-16 11:00:23 +00:00
feat: logger
This commit is contained in:
parent
80a428855f
commit
68b3223268
@ -1,3 +1,4 @@
|
|||||||
|
local Logger = require("harpoon.logger")
|
||||||
local Path = require("plenary.path")
|
local Path = require("plenary.path")
|
||||||
local function normalize_path(buf_name, root)
|
local function normalize_path(buf_name, root)
|
||||||
return Path:new(buf_name):make_relative(root)
|
return Path:new(buf_name):make_relative(root)
|
||||||
@ -85,6 +86,7 @@ function M.get_default_config()
|
|||||||
---@param list HarpoonList
|
---@param list HarpoonList
|
||||||
---@param options HarpoonListFileOptions
|
---@param options HarpoonListFileOptions
|
||||||
select = function(list_item, list, options)
|
select = function(list_item, list, options)
|
||||||
|
Logger:log("config_default#select", list_item, list.name, options)
|
||||||
options = options or {}
|
options = options or {}
|
||||||
if list_item == nil then
|
if list_item == nil then
|
||||||
return
|
return
|
||||||
@ -142,6 +144,8 @@ function M.get_default_config()
|
|||||||
config.get_root_dir()
|
config.get_root_dir()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Logger:log("config_default#add", name)
|
||||||
|
|
||||||
local bufnr = vim.fn.bufnr(name, false)
|
local bufnr = vim.fn.bufnr(name, false)
|
||||||
|
|
||||||
local pos = { 1, 0 }
|
local pos = { 1, 0 }
|
||||||
@ -165,8 +169,12 @@ function M.get_default_config()
|
|||||||
|
|
||||||
if item then
|
if item then
|
||||||
local pos = vim.api.nvim_win_get_cursor(0)
|
local pos = vim.api.nvim_win_get_cursor(0)
|
||||||
|
|
||||||
|
Logger:log("config_default#BufLeave updating position", bufnr, bufname, item, "to position", pos)
|
||||||
|
|
||||||
item.context.row = pos[1]
|
item.context.row = pos[1]
|
||||||
item.context.col = pos[2]
|
item.context.col = pos[2]
|
||||||
|
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
local Log = require("harpoon.logger")
|
||||||
local Ui = require("harpoon.ui")
|
local Ui = require("harpoon.ui")
|
||||||
local Data = require("harpoon.data")
|
local Data = require("harpoon.data")
|
||||||
local Config = require("harpoon.config")
|
local Config = require("harpoon.config")
|
||||||
@ -10,6 +11,7 @@ local HarpoonGroup = require("harpoon.autocmd")
|
|||||||
---@field ui HarpoonUI
|
---@field ui HarpoonUI
|
||||||
---@field listeners HarpoonListeners
|
---@field listeners HarpoonListeners
|
||||||
---@field data HarpoonData
|
---@field data HarpoonData
|
||||||
|
---@field logger HarpoonLog
|
||||||
---@field lists {[string]: {[string]: HarpoonList}}
|
---@field lists {[string]: {[string]: HarpoonList}}
|
||||||
---@field hooks_setup boolean
|
---@field hooks_setup boolean
|
||||||
local Harpoon = {}
|
local Harpoon = {}
|
||||||
@ -23,6 +25,7 @@ function Harpoon:new()
|
|||||||
local harpoon = setmetatable({
|
local harpoon = setmetatable({
|
||||||
config = config,
|
config = config,
|
||||||
data = Data.Data:new(),
|
data = Data.Data:new(),
|
||||||
|
logger = Log,
|
||||||
ui = Ui:new(config.settings),
|
ui = Ui:new(config.settings),
|
||||||
listeners = Listeners.listeners,
|
listeners = Listeners.listeners,
|
||||||
lists = {},
|
lists = {},
|
||||||
@ -38,15 +41,6 @@ function Harpoon:setup(partial_config)
|
|||||||
self.config = Config.merge_config(partial_config, self.config)
|
self.config = Config.merge_config(partial_config, self.config)
|
||||||
self.ui:configure(self.config.settings)
|
self.ui:configure(self.config.settings)
|
||||||
|
|
||||||
local highlights = {
|
|
||||||
HarpoonWindow = { default = true, link = "NormalFloat" },
|
|
||||||
HarpoonBorder = { default = true, link = "FloatBorder" },
|
|
||||||
HarpoonTitle = { default = true, link = "FloatTitle" },
|
|
||||||
}
|
|
||||||
for k, v in pairs(highlights) do
|
|
||||||
vim.api.nvim_set_hl(0, k, v)
|
|
||||||
end
|
|
||||||
|
|
||||||
---TODO: should we go through every seen list and update its config?
|
---TODO: should we go through every seen list and update its config?
|
||||||
|
|
||||||
if self.hooks_setup == false then
|
if self.hooks_setup == false then
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
local Log = 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)
|
||||||
|
39
lua/harpoon/logger.lua
Normal file
39
lua/harpoon/logger.lua
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
---@class HarpoonLog
|
||||||
|
---@field lines string[]
|
||||||
|
local HarpoonLog = {}
|
||||||
|
|
||||||
|
HarpoonLog.__index = HarpoonLog
|
||||||
|
|
||||||
|
---@return HarpoonLog
|
||||||
|
function HarpoonLog:new()
|
||||||
|
local logger = setmetatable({
|
||||||
|
lines = {},
|
||||||
|
}, self)
|
||||||
|
|
||||||
|
return logger
|
||||||
|
end
|
||||||
|
|
||||||
|
---@vararg any
|
||||||
|
function HarpoonLog:log(...)
|
||||||
|
|
||||||
|
local msg = {}
|
||||||
|
for i = 1, select("#", ...) do
|
||||||
|
table.insert(msg, vim.inspect(select(i, ...)))
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(self.lines, table.concat(msg, " "))
|
||||||
|
end
|
||||||
|
|
||||||
|
function HarpoonLog:clear()
|
||||||
|
self.lines = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function HarpoonLog:show()
|
||||||
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
|
print(vim.inspect(self.lines))
|
||||||
|
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, self.lines)
|
||||||
|
vim.api.nvim_win_set_buf(0, bufnr)
|
||||||
|
end
|
||||||
|
|
||||||
|
return HarpoonLog:new()
|
@ -1,5 +1,6 @@
|
|||||||
local popup = require("plenary").popup
|
local popup = require("plenary").popup
|
||||||
local Buffer = require("harpoon.buffer")
|
local Buffer = require("harpoon.buffer")
|
||||||
|
local Logger = require("harpoon.logger")
|
||||||
local DEFAULT_WINDOW_WIDTH = 69 -- nice
|
local DEFAULT_WINDOW_WIDTH = 69 -- nice
|
||||||
|
|
||||||
---@class HarpoonUI
|
---@class HarpoonUI
|
||||||
@ -30,6 +31,10 @@ function HarpoonUI:close_menu()
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.closing = true
|
self.closing = true
|
||||||
|
Logger:log("ui#close_menu name: ", self.active_list.name, "win and bufnr", {
|
||||||
|
win = self.win_id,
|
||||||
|
bufnr = self.bufnr
|
||||||
|
})
|
||||||
|
|
||||||
if self.bufnr ~= nil and vim.api.nvim_buf_is_valid(self.bufnr) then
|
if self.bufnr ~= nil and vim.api.nvim_buf_is_valid(self.bufnr) then
|
||||||
vim.api.nvim_buf_delete(self.bufnr, { force = true })
|
vim.api.nvim_buf_delete(self.bufnr, { force = true })
|
||||||
@ -90,11 +95,10 @@ function HarpoonUI:_create_window()
|
|||||||
return win_id, bufnr
|
return win_id, bufnr
|
||||||
end
|
end
|
||||||
|
|
||||||
local count = 0
|
|
||||||
|
|
||||||
---@param list? HarpoonList
|
---@param list? HarpoonList
|
||||||
function HarpoonUI:toggle_quick_menu(list)
|
function HarpoonUI:toggle_quick_menu(list)
|
||||||
count = count + 1
|
|
||||||
|
Logger:log("ui#toggle_quick_menu", list and list.name)
|
||||||
|
|
||||||
if list == nil or self.win_id ~= nil then
|
if list == nil or self.win_id ~= nil then
|
||||||
if self.settings.save_on_toggle then
|
if self.settings.save_on_toggle then
|
||||||
@ -129,6 +133,7 @@ end
|
|||||||
|
|
||||||
function HarpoonUI:save()
|
function HarpoonUI:save()
|
||||||
local list = Buffer.get_contents(self.bufnr)
|
local list = Buffer.get_contents(self.bufnr)
|
||||||
|
Logger:log("ui#save", list)
|
||||||
self.active_list:resolve_displayed(list)
|
self.active_list:resolve_displayed(list)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user