diff --git a/lua/hawtkeys/init.lua b/lua/hawtkeys/init.lua index 5ba18bb..ee3217f 100644 --- a/lua/hawtkeys/init.lua +++ b/lua/hawtkeys/init.lua @@ -12,6 +12,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 @@ -27,6 +28,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 = { @@ -64,6 +66,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..7a27f09 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 and 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