update logging for init and mark

This commit is contained in:
Raigo Jerva 2021-04-28 22:04:24 +03:00
parent 0b61951167
commit 350c7feea4
No known key found for this signature in database
GPG Key ID: 2156679E782853EC
4 changed files with 23 additions and 7 deletions

View File

@ -11,7 +11,7 @@ end
local function set_log_level()
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
if level == log_level then

View File

@ -55,6 +55,7 @@ local function merge_tables(...)
end
local function ensure_correct_config(config)
log.debug("_ensure_correct_config()")
local projects = config.projects
if projects[vim.loop.cwd()] == nil then
log.trace("ensure_correct_config(): No config found for:", vim.loop.cwd())
@ -96,6 +97,9 @@ local function ensure_correct_config(config)
end
local function expand_dir(config)
log.debug("_expand_dir()")
log.trace("_expand_dir(): Config pre-expansion:", config)
local projects = config.projects or {}
for k in pairs(projects) do
local expanded_path = Path.new(k):expand()
@ -105,6 +109,7 @@ local function expand_dir(config)
end
end
log.trace("_expand_dir(): Config post-expansion:", config)
return config
end

View File

@ -10,22 +10,24 @@ local callbacks = {}
-- I am trying to avoid over engineering the whole thing. We will likely only
-- need one event emitted
local function emit_changed()
log.debug("_emit_changed()")
if harpoon.get_global_settings().save_on_change then
harpoon.save()
end
if not callbacks["changed"] then
log.debug("emit_changed(): no callbacks for 'changed', returning")
log.debug("_emit_changed(): no callbacks for 'changed', returning")
return
end
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()
end
end
local function filter_empty_string(list)
log.debug("_filter_empty_string()")
local next = {}
for idx = 1, #list do
if list[idx] ~= "" then
@ -49,7 +51,7 @@ local function get_first_empty_slot()
end
local function get_buf_name(id)
log.debug("get_buf_name():", id)
log.debug("_get_buf_name():", id)
if id == nil then
return utils.normalize_path(vim.fn.bufname(vim.fn.bufnr()))
elseif type(id) == "string" then
@ -68,6 +70,12 @@ end
local function create_mark(filename)
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 {
filename = filename,
row = cursor_pos[2],
@ -89,8 +97,9 @@ local function mark_exists(buf_name)
end
local function validate_buf_name(buf_name)
log.debug("_validate_buf_name():", buf_name)
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
end
end
@ -113,7 +122,7 @@ M.get_index_of = function(item)
return nil
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
item = item + 1
end
@ -343,7 +352,7 @@ M.on = function(event, cb)
end
table.insert(callbacks[event], cb)
log.trace(callbacks)
log.trace("on(): All callbacks:", callbacks)
end
return M

View File

@ -35,11 +35,13 @@ local function create_window()
end
local function get_menu_items()
log.debug("_get_menu_items()")
local lines = vim.api.nvim_buf_get_lines(Harpoon_bufh, 0, -1, true)
local indices = {}
for idx = 1, #lines do
local space_location = string.find(lines[idx], " ")
log.trace("_get_menu_items():", idx, space_location)
if space_location ~= nil then
table.insert(indices, string.sub(lines[idx], space_location + 1))