From 78ab48ba6ced1b08194f0a5e6bedda0d368bbf54 Mon Sep 17 00:00:00 2001 From: tris203 Date: Tue, 2 Jan 2024 23:47:41 +0000 Subject: [PATCH 1/2] feat: start logging --- lua/hawtkeys/init.lua | 3 +++ lua/hawtkeys/ts.lua | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lua/hawtkeys/init.lua b/lua/hawtkeys/init.lua index 48c15d4..7ae5cf1 100644 --- a/lua/hawtkeys/init.lua +++ b/lua/hawtkeys/init.lua @@ -14,6 +14,7 @@ local M = {} ---@field customMaps { [string] : TSKeyMapArgs | WhichKeyMapargs | LazyKeyMapArgs } | nil ---@field highlights HawtKeyHighlights ---@field lhsBlacklist string[] +---@field debug boolean ---@class HawtKeyHighlights ---@field HawtkeysMatchGreat vim.api.keyset.highlight | nil @@ -29,6 +30,7 @@ local M = {} ---@field customMaps { [string] : TSKeyMapArgs | WhichKeyMapargs | LazyKeyMapArgs } | nil ---@field highlights HawtKeyHighlights | nil ---@field lhsBlacklist string[] | nil +---@field debug boolean | nil ---@type { [string] : TSKeyMapArgs | WhichKeyMapargs | LazyKeyMapArgs } local _defaultSet = { @@ -66,6 +68,7 @@ local defaultConfig = { Þ is used internally by whickkey to map NOP functions for menu popup timeout ]] lhsBlacklist = { "", "Þ" }, + debug = false, } local auGroup = vim.api.nvim_create_augroup("hawtkeys", { clear = true }) diff --git a/lua/hawtkeys/ts.lua b/lua/hawtkeys/ts.lua index a1a8a14..4bbaf83 100644 --- a/lua/hawtkeys/ts.lua +++ b/lua/hawtkeys/ts.lua @@ -5,6 +5,18 @@ local utils = require("hawtkeys.utils") local hawtkeys = require("hawtkeys") local ts = require("nvim-treesitter.compat") local tsQuery = require("nvim-treesitter.query") +local logger +if hawtkeys.config.debug then + logger = require("plenary.log").new({ + plugin = "hawtkeys", + level = "trace", + }) +else + logger = require("plenary.log").new({ + plugin = "hawtkeys", + level = "warn", + }) +end ---@alias VimModes 'n' | 'x' | 'v' | 'i' @@ -129,18 +141,23 @@ end ---@param filePath string ---@return HawtkeysKeyMapData[] local function find_maps_in_file(filePath) + logger.debug("Scanning file: " .. filePath) if scannedFiles[filePath] then + logger.debug("Already scanned file: " .. filePath) -- already scanned return {} end scannedFiles[filePath] = true --if not a lua file, return empty table if not string.match(filePath, "%.lua$") then + logger.debug("Not a lua file: " .. filePath) return {} end local fileContent = Path:new(filePath):read() local parser = vim.treesitter.get_string_parser(fileContent, "lua", {}) -- Get the Lua parser + logger.debug("Parsing file: " .. filePath) local tree = parser:parse()[1]:root() + logger.debug("Parsed file: " .. filePath) local tsKeymaps = {} -- TODO: This currently doesnt always work, as the options for helper functions are different, -- need to use TS to resolve it back to a native keymap From 1f770f671fd8d074c09d6922aa124059d291f9d9 Mon Sep 17 00:00:00 2001 From: tris203 Date: Wed, 3 Jan 2024 23:44:37 +0000 Subject: [PATCH 2/2] fix: minor test issue --- lua/hawtkeys/ts.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/hawtkeys/ts.lua b/lua/hawtkeys/ts.lua index 4bbaf83..7a27f09 100644 --- a/lua/hawtkeys/ts.lua +++ b/lua/hawtkeys/ts.lua @@ -6,7 +6,7 @@ local hawtkeys = require("hawtkeys") local ts = require("nvim-treesitter.compat") local tsQuery = require("nvim-treesitter.query") local logger -if hawtkeys.config.debug then +if hawtkeys.config and hawtkeys.config.debug then logger = require("plenary.log").new({ plugin = "hawtkeys", level = "trace",