Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding logging flag #72

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lua/hawtkeys/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down Expand Up @@ -64,6 +66,7 @@ local defaultConfig = {
Þ is used internally by whickkey to map NOP functions for menu popup timeout
]]
lhsBlacklist = { "<plug>", "Þ" },
debug = false,
}

local auGroup = vim.api.nvim_create_augroup("hawtkeys", { clear = true })
Expand Down
17 changes: 17 additions & 0 deletions lua/hawtkeys/ts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down
Loading