Skip to content

Commit

Permalink
refactor: tidy testing, add reset, add complexIndex type
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 committed Dec 19, 2023
1 parent 1738277 commit 445d15c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
17 changes: 10 additions & 7 deletions lua/hawtkeys/tests/set_maps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ local normalMap = function(lhs, rhs)
end
normalMap("<leader>3", ':lua print("3 pressed")<CR>')

local kmap = vim.api
local shortIndex = vim.api

kmap.nvim_set_keymap(
shortIndex.nvim_set_keymap(
"n",
"<leader>4",
':lua print("4 pressed")<CR>',
{ noremap = true, silent = true }
)

local nmap = vim.api.nvim_set_keymap
local shortFunc = vim.api.nvim_set_keymap

nmap(
shortFunc(
"n",
"<leader>5",
':lua print("5 pressed")<CR>',
Expand All @@ -39,10 +39,13 @@ local whichkey = require("which-key")
whichkey.register({
["<leader>"] = {
["6"] = { ':lua print("6 pressed")<CR>', "Print 6" },
["7"] = { ':lua print("7 pressed")<CR>', "Print 7" },
},
})({
})

return {
"plugin/example",
keys = {
{ "<leader>7", ":lua print('7 pressed" },
{ "<leader>8", ":lua print('8 pressed" },
},
})
}
1 change: 1 addition & 0 deletions lua/hawtkeys/tests/test_ts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ local ts = require("hawtkeys.ts")

local maps = ts.find_maps_in_file("lua/hawtkeys/tests/set_maps.lua")
print(vim.inspect(maps))
ts.reset_scanned_files()
22 changes: 17 additions & 5 deletions lua/hawtkeys/ts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ local tsQuery = require("nvim-treesitter.query")

---@alias vimModes 'n' | 'x' | 'v' | 'i'

---@alias setMethods 'dot_index_expression' | 'index_expression' | 'function_call'
---@alias setMethods 'dot_index_expression' | 'expression_list' | 'function_call'

---@alias complexIndex table<number>

---@class keyMapArgs
---@field modeIndex number | vimModes
---@field lhsIndex number
---@field rhsIndex number
---@field lhsIndex number | complexIndex
---@field rhsIndex number | complexIndex
---@field optsIndex number|nil
---@field method setMethods

Expand All @@ -39,18 +41,24 @@ local keyMapSet = {
rhsIndex = 2,
method = "function_call",
}, --method 3
["kmap.nvim_set_keymap"] = {
["shortIndex.nvim_set_keymap"] = {
modeIndex = 1,
lhsIndex = 2,
rhsIndex = 3,
method = "dot_index_expression",
}, --method 4
["nmap"] = {
["shortFunc"] = {
modeIndex = "n",
lhsIndex = 1,
rhsIndex = 2,
method = "function_call",
}, -- method 5
["nmap"] = {
modeIndex = "n",
lhsIndex = 1,
rhsIndex = 2,
method = "function_call",
}, -- for my personal config - used in lsp-setup
}

---@type table<string, boolean>
Expand Down Expand Up @@ -329,6 +337,10 @@ function M.get_all_keymaps()
return returnKeymaps
end

M.reset_scanned_files = function()
scannedFiles = {}
end

M.find_maps_in_file = find_maps_in_file

return M

0 comments on commit 445d15c

Please sign in to comment.