mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 10:00:29 +00:00
update logging for init and mark
This commit is contained in:
parent
0b61951167
commit
350c7feea4
@ -11,7 +11,7 @@ end
|
|||||||
|
|
||||||
local function set_log_level()
|
local function set_log_level()
|
||||||
local log_levels = { "trace", "debug", "info", "warning", "error", "fatal" }
|
local log_levels = { "trace", "debug", "info", "warning", "error", "fatal" }
|
||||||
local log_level = vim.g.harpoon_log_level
|
local log_level = vim.g.harpoon_log_level or vim.env.HARPOON_LOG
|
||||||
|
|
||||||
for _, level in pairs(log_levels) do
|
for _, level in pairs(log_levels) do
|
||||||
if level == log_level then
|
if level == log_level then
|
||||||
|
@ -55,6 +55,7 @@ local function merge_tables(...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function ensure_correct_config(config)
|
local function ensure_correct_config(config)
|
||||||
|
log.debug("_ensure_correct_config()")
|
||||||
local projects = config.projects
|
local projects = config.projects
|
||||||
if projects[vim.loop.cwd()] == nil then
|
if projects[vim.loop.cwd()] == nil then
|
||||||
log.trace("ensure_correct_config(): No config found for:", vim.loop.cwd())
|
log.trace("ensure_correct_config(): No config found for:", vim.loop.cwd())
|
||||||
@ -96,6 +97,9 @@ local function ensure_correct_config(config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function expand_dir(config)
|
local function expand_dir(config)
|
||||||
|
log.debug("_expand_dir()")
|
||||||
|
log.trace("_expand_dir(): Config pre-expansion:", config)
|
||||||
|
|
||||||
local projects = config.projects or {}
|
local projects = config.projects or {}
|
||||||
for k in pairs(projects) do
|
for k in pairs(projects) do
|
||||||
local expanded_path = Path.new(k):expand()
|
local expanded_path = Path.new(k):expand()
|
||||||
@ -105,6 +109,7 @@ local function expand_dir(config)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
log.trace("_expand_dir(): Config post-expansion:", config)
|
||||||
return config
|
return config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -10,22 +10,24 @@ local callbacks = {}
|
|||||||
-- I am trying to avoid over engineering the whole thing. We will likely only
|
-- I am trying to avoid over engineering the whole thing. We will likely only
|
||||||
-- need one event emitted
|
-- need one event emitted
|
||||||
local function emit_changed()
|
local function emit_changed()
|
||||||
|
log.debug("_emit_changed()")
|
||||||
if harpoon.get_global_settings().save_on_change then
|
if harpoon.get_global_settings().save_on_change then
|
||||||
harpoon.save()
|
harpoon.save()
|
||||||
end
|
end
|
||||||
|
|
||||||
if not callbacks["changed"] then
|
if not callbacks["changed"] then
|
||||||
log.debug("emit_changed(): no callbacks for 'changed', returning")
|
log.debug("_emit_changed(): no callbacks for 'changed', returning")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
for idx, cb in pairs(callbacks["changed"]) do
|
for idx, cb in pairs(callbacks["changed"]) do
|
||||||
log.debug(string.format("emit_changed(): Running callback #%d for 'changed'", idx))
|
log.debug(string.format("_emit_changed(): Running callback #%d for 'changed'", idx))
|
||||||
cb()
|
cb()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function filter_empty_string(list)
|
local function filter_empty_string(list)
|
||||||
|
log.debug("_filter_empty_string()")
|
||||||
local next = {}
|
local next = {}
|
||||||
for idx = 1, #list do
|
for idx = 1, #list do
|
||||||
if list[idx] ~= "" then
|
if list[idx] ~= "" then
|
||||||
@ -49,7 +51,7 @@ local function get_first_empty_slot()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_buf_name(id)
|
local function get_buf_name(id)
|
||||||
log.debug("get_buf_name():", id)
|
log.debug("_get_buf_name():", id)
|
||||||
if id == nil then
|
if id == nil then
|
||||||
return utils.normalize_path(vim.fn.bufname(vim.fn.bufnr()))
|
return utils.normalize_path(vim.fn.bufname(vim.fn.bufnr()))
|
||||||
elseif type(id) == "string" then
|
elseif type(id) == "string" then
|
||||||
@ -68,6 +70,12 @@ end
|
|||||||
|
|
||||||
local function create_mark(filename)
|
local function create_mark(filename)
|
||||||
local cursor_pos = vim.fn.getcurpos()
|
local cursor_pos = vim.fn.getcurpos()
|
||||||
|
log.debug(string.format(
|
||||||
|
"_create_mark(): Creating mark at row: %d, col: %d for %s",
|
||||||
|
cursor_pos[2],
|
||||||
|
cursor_pos[4],
|
||||||
|
filename
|
||||||
|
))
|
||||||
return {
|
return {
|
||||||
filename = filename,
|
filename = filename,
|
||||||
row = cursor_pos[2],
|
row = cursor_pos[2],
|
||||||
@ -89,8 +97,9 @@ local function mark_exists(buf_name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function validate_buf_name(buf_name)
|
local function validate_buf_name(buf_name)
|
||||||
|
log.debug("_validate_buf_name():", buf_name)
|
||||||
if buf_name == "" or buf_name == nil then
|
if buf_name == "" or buf_name == nil then
|
||||||
log.error("validate_buf_name(): Not a valid name for a mark,", buf_name)
|
log.error("_validate_buf_name(): Not a valid name for a mark,", buf_name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -113,7 +122,7 @@ M.get_index_of = function(item)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO move this to a "harpoon_" prefix?
|
-- TODO move this to a "harpoon_" prefix or global config?
|
||||||
if vim.g.manage_a_mark_zero_index then
|
if vim.g.manage_a_mark_zero_index then
|
||||||
item = item + 1
|
item = item + 1
|
||||||
end
|
end
|
||||||
@ -343,7 +352,7 @@ M.on = function(event, cb)
|
|||||||
end
|
end
|
||||||
|
|
||||||
table.insert(callbacks[event], cb)
|
table.insert(callbacks[event], cb)
|
||||||
log.trace(callbacks)
|
log.trace("on(): All callbacks:", callbacks)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -35,11 +35,13 @@ local function create_window()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_menu_items()
|
local function get_menu_items()
|
||||||
|
log.debug("_get_menu_items()")
|
||||||
local lines = vim.api.nvim_buf_get_lines(Harpoon_bufh, 0, -1, true)
|
local lines = vim.api.nvim_buf_get_lines(Harpoon_bufh, 0, -1, true)
|
||||||
local indices = {}
|
local indices = {}
|
||||||
|
|
||||||
for idx = 1, #lines do
|
for idx = 1, #lines do
|
||||||
local space_location = string.find(lines[idx], " ")
|
local space_location = string.find(lines[idx], " ")
|
||||||
|
log.trace("_get_menu_items():", idx, space_location)
|
||||||
|
|
||||||
if space_location ~= nil then
|
if space_location ~= nil then
|
||||||
table.insert(indices, string.sub(lines[idx], space_location + 1))
|
table.insert(indices, string.sub(lines[idx], space_location + 1))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user