From 140d1ca10948a24bb09e5e4365a69c82db187c12 Mon Sep 17 00:00:00 2001 From: Raigo Jerva Date: Mon, 3 May 2021 21:45:24 +0300 Subject: [PATCH] adjust log levels - set every function call to trace, logs in between as bebug --- lua/harpoon/init.lua | 22 +++++++++++----------- lua/harpoon/mark.lua | 45 ++++++++++++++++++++++---------------------- lua/harpoon/term.lua | 6 +++--- lua/harpoon/ui.lua | 14 +++++++------- 4 files changed, 43 insertions(+), 44 deletions(-) diff --git a/lua/harpoon/init.lua b/lua/harpoon/init.lua index 926ede2..112d6e0 100644 --- a/lua/harpoon/init.lua +++ b/lua/harpoon/init.lua @@ -46,11 +46,11 @@ local function merge_table_impl(t1, t2) end local function merge_tables(...) + log.trace("_merge_tables()") local out = {} for i = 1, select("#",...) do merge_table_impl(out, select(i, ...)) end - log.trace("_merge_tables(): Output", out) return out end @@ -58,7 +58,7 @@ local function ensure_correct_config(config) log.trace("_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()) + log.debug("ensure_correct_config(): No config found for:", vim.loop.cwd()) projects[vim.loop.cwd()] = { mark = { marks = {} @@ -71,12 +71,12 @@ local function ensure_correct_config(config) local proj = projects[vim.loop.cwd()] if proj.mark == nil then - log.trace("ensure_correct_config(): No marks found for", vim.loop.cwd()) + log.debug("ensure_correct_config(): No marks found for", vim.loop.cwd()) proj.mark = {marks = {}} end if proj.term == nil then - log.trace("ensure_correct_config(): No terminal commands found for", vim.loop.cwd()) + log.debug("ensure_correct_config(): No terminal commands found for", vim.loop.cwd()) proj.term = {cmds = {}} end @@ -113,7 +113,7 @@ local function expand_dir(config) end M.save = function() - log.debug("save(): Saving cache config to", cache_config) + log.trace("save(): Saving cache config to", cache_config) Path:new(cache_config):write(vim.fn.json_encode(HarpoonConfig), "w") end @@ -124,7 +124,7 @@ end -- 1. saved. Where do we save? M.setup = function(config) - log.debug("setup(): Setting up...") + log.trace("setup(): Setting up...") if not config then config = {} @@ -159,26 +159,26 @@ M.setup = function(config) ensure_correct_config(complete_config) HarpoonConfig = complete_config - log.trace("setup(): Complete config", HarpoonConfig) + log.debug("setup(): Complete config", HarpoonConfig) end M.get_global_settings = function() - log.debug("get_global_settings()") + log.trace("get_global_settings()") return HarpoonConfig.global_settings end M.get_term_config = function() - log.debug("get_term_config()") + log.trace("get_term_config()") return ensure_correct_config(HarpoonConfig).projects[vim.loop.cwd()].term end M.get_mark_config = function() - log.debug("get_mark_config()") + log.trace("get_mark_config()") return ensure_correct_config(HarpoonConfig).projects[vim.loop.cwd()].mark end M.get_menu_config = function() - log.debug("get_menu_config()") + log.trace("get_menu_config()") return HarpoonConfig.menu or {} end diff --git a/lua/harpoon/mark.lua b/lua/harpoon/mark.lua index 98b0d98..b605e99 100644 --- a/lua/harpoon/mark.lua +++ b/lua/harpoon/mark.lua @@ -70,7 +70,7 @@ end local function create_mark(filename) local cursor_pos = vim.fn.getcurpos() - log.debug(string.format( + log.trace(string.format( "_create_mark(): Creating mark at row: %d, col: %d for %s", cursor_pos[2], cursor_pos[4], @@ -87,12 +87,12 @@ local function mark_exists(buf_name) log.trace("_mark_exists()") for idx = 1, M.get_length() do if M.get_marked_file_name(idx) == buf_name then - log.trace("_mark_exists(): Mark exists", buf_name) + log.debug("_mark_exists(): Mark exists", buf_name) return true end end - log.trace("_mark_exists(): Mark doesn't exist", buf_name) + log.debug("_mark_exists(): Mark doesn't exist", buf_name) return false end @@ -106,7 +106,7 @@ local function validate_buf_name(buf_name) end M.get_index_of = function(item) - log.debug("get_index_of():", item) + log.trace("get_index_of():", item) if item == nil then log.error("get_index_of(): Function has been supplied with a nil value.") error("You have provided a nil value to Harpoon, please provide a string rep of the file or the file idx.") @@ -138,7 +138,7 @@ M.get_index_of = function(item) end M.status = function() - log.debug("status()") + log.trace("status()") local idx = M.get_index_of(get_buf_name()) if M.valid_index(idx) then @@ -148,7 +148,7 @@ M.status = function() end M.valid_index = function(idx) - log.debug("valid_index():", idx) + log.trace("valid_index():", idx) if idx == nil then return false end @@ -159,7 +159,7 @@ end M.add_file = function(file_name_or_buf_id) local buf_name = get_buf_name(file_name_or_buf_id) - log.info("add_file():", buf_name) + log.trace("add_file():", buf_name) if M.valid_index(M.get_index_of(buf_name)) then -- we don't alter file layout. @@ -176,7 +176,7 @@ end -- _emit_on_changed == false should only be used internally M.remove_empty_tail = function(_emit_on_changed) - log.debug("remove_empty_tail()") + log.trace("remove_empty_tail()") _emit_on_changed = _emit_on_changed == nil or _emit_on_changed local config = harpoon.get_mark_config() local found = false @@ -199,7 +199,7 @@ M.remove_empty_tail = function(_emit_on_changed) end M.store_offset = function() - log.debug("store_offset()") + log.trace("store_offset()") local ok, res = pcall(function() local buf_name = get_buf_name() local idx = M.get_index_of(buf_name) @@ -223,6 +223,7 @@ end M.rm_file = function(file_name_or_buf_id) local buf_name = get_buf_name(file_name_or_buf_id) local idx = M.get_index_of(buf_name) + log.trace("rm_file(): Removing mark at id", idx) if not M.valid_index(idx) then log.debug("rm_file(): No mark exists for id", file_name_or_buf_id) @@ -232,18 +233,17 @@ M.rm_file = function(file_name_or_buf_id) harpoon.get_mark_config().marks[idx] = create_mark("") M.remove_empty_tail(false) emit_changed() - log.info("rm_file(): Removed mark at id", idx) end M.clear_all = function() harpoon.get_mark_config().marks = {} - log.info("clear_all(): Clearing all marks.") + log.trace("clear_all(): Clearing all marks.") emit_changed() end --- ENTERPRISE PROGRAMMING M.get_marked_file = function(idxOrName) - log.debug("get_marked_file():", idxOrName) + log.trace("get_marked_file():", idxOrName) if type(idxOrName) == "string" then idxOrName = M.get_index_of(idxOrName) end @@ -252,12 +252,12 @@ end M.get_marked_file_name = function(idx) local mark = harpoon.get_mark_config().marks[idx] - log.debug("get_marked_file_name():", mark and mark.filename) + log.trace("get_marked_file_name():", mark and mark.filename) return mark and mark.filename end M.get_length = function() - log.debug("get_length()") + log.trace("get_length()") return table.maxn(harpoon.get_mark_config().marks) end @@ -266,7 +266,7 @@ M.set_current_at = function(idx) local buf_name = get_buf_name() local current_idx = M.get_index_of(buf_name) - log.info("set_current_at(): Setting id", idx, buf_name) + log.trace("set_current_at(): Setting id", idx, buf_name) -- Remove it if it already exists if M.valid_index(current_idx) then @@ -285,6 +285,7 @@ M.set_current_at = function(idx) end M.to_quickfix_list = function() + log.trace("to_quickfix_list(): Sending marks to quickfix list.") local config = harpoon.get_mark_config() local file_list = filter_empty_string(config.marks) local qf_list = {} @@ -297,13 +298,12 @@ M.to_quickfix_list = function() col = mark.col, } end - log.debug("to_quickfix_list(): Sending marks to quickfix list.") + log.debug("to_quickfix_list(): qf_list:", qf_list) vim.fn.setqflist(qf_list) end M.set_mark_list = function(new_list) - log.debug("set_mark_list()") - log.trace("set_mark_list(): new_list", new_list) + log.trace("set_mark_list(): New list:", new_list) local config = harpoon.get_mark_config() @@ -324,8 +324,7 @@ end M.toggle_file = function(file_name_or_buf_id) local buf_name = get_buf_name(file_name_or_buf_id) - - log.info("toggle_file():", buf_name) + log.trace("toggle_file():", buf_name) validate_buf_name(buf_name) @@ -341,19 +340,19 @@ M.toggle_file = function(file_name_or_buf_id) end M.get_current_index = function() - log.debug("get_current_index()") + log.trace("get_current_index()") return M.get_index_of(vim.fn.bufname(vim.fn.bufnr())) end M.on = function(event, cb) - log.debug("on():", event) + log.trace("on():", event) if not callbacks[event] then log.debug("on(): no callbacks yet for", event) callbacks[event] = {} end table.insert(callbacks[event], cb) - log.trace("on(): All callbacks:", callbacks) + log.debug("on(): All callbacks:", callbacks) end return M diff --git a/lua/harpoon/term.lua b/lua/harpoon/term.lua index b317cea..e18d490 100644 --- a/lua/harpoon/term.lua +++ b/lua/harpoon/term.lua @@ -51,14 +51,14 @@ local function find_terminal(idx) end M.gotoTerminal = function(idx) - log.info("gotoTerminal(): Terminal:", idx) + log.trace("gotoTerminal(): Terminal:", idx) local term_handle = find_terminal(idx) vim.api.nvim_set_current_buf(term_handle.buf_id) end M.sendCommand = function(idx, cmd, ...) - log.info("sendCommand(): Terminal:", idx) + log.trace("sendCommand(): Terminal:", idx) local term_handle = find_terminal(idx) if type(cmd) == "number" then @@ -66,7 +66,7 @@ M.sendCommand = function(idx, cmd, ...) end if cmd then - log.trace("sendCommand:", cmd) + log.debug("sendCommand:", cmd) vim.fn.chansend(term_handle.term_id, string.format(cmd, ...)) end end diff --git a/lua/harpoon/ui.lua b/lua/harpoon/ui.lua index f007f12..2b1625d 100644 --- a/lua/harpoon/ui.lua +++ b/lua/harpoon/ui.lua @@ -41,7 +41,7 @@ local function get_menu_items() for idx = 1, #lines do local space_location = string.find(lines[idx], ' ') - log.trace("_get_menu_items():", idx, space_location) + log.debug("_get_menu_items():", idx, space_location) if space_location ~= nil then table.insert(indices, string.sub(lines[idx], space_location + 1)) @@ -54,7 +54,7 @@ end M.toggle_quick_menu = function() - log.info("toggle_quick_menu()") + log.trace("toggle_quick_menu()") if Harpoon_win_id ~= nil and vim.api.nvim_win_is_valid(Harpoon_win_id) then local global_config = harpoon.get_global_settings() @@ -94,12 +94,12 @@ M.toggle_quick_menu = function() end M.on_menu_save = function() - log.debug("on_menu_save()") + log.trace("on_menu_save()") Marked.set_mark_list(get_menu_items()) end M.nav_file = function(id) - log.info("nav_file(): Navigating to", id) + log.trace("nav_file(): Navigating to", id) local idx = Marked.get_index_of(id) if not Marked.valid_index(idx) then log.debug("nav_file(): No mark exists for id", id) @@ -113,7 +113,7 @@ M.nav_file = function(id) vim.api.nvim_set_current_buf(buf_id) if set_row and mark.row and mark.col then vim.cmd(string.format(":call cursor(%d, %d)", mark.row, mark.col)) - log.trace(string.format("nav_file(): Setting cursor to row: %d, col: %d", mark.row, mark.col)) + log.debug(string.format("nav_file(): Setting cursor to row: %d, col: %d", mark.row, mark.col)) end end @@ -164,7 +164,7 @@ function M.close_notification(bufnr) end M.nav_next = function() - log.info("nav_next()") + log.trace("nav_next()") local current_index = Marked.get_current_index() local number_of_items = Marked.get_length() @@ -181,7 +181,7 @@ M.nav_next = function() end M.nav_prev = function() - log.info("nav_prev()") + log.trace("nav_prev()") local current_index = Marked.get_current_index() local number_of_items = Marked.get_length()