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: testing and configurable iterative mapping #26

Merged
merged 17 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 14 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 .githooks/tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

make test
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test

on:
push:
branches:
- "main"
pull_request:
branches:
- "main"

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
nvim-versions: ['stable', 'nightly']
name: Plenary Tests
steps:
- name: checkout
uses: actions/checkout@v3

- uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: ${{ matrix.nvim-versions }}

- name: run tests
run: make test
7 changes: 7 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"diagnostics.globals": [
"describe",
"it",
"before_each"
]
}
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
TESTS_INIT=tests/minimal_init.lua
TESTS_DIR=tests/

.PHONY: test

test:
@nvim \
--headless \
--noplugin \
-u ${TESTS_INIT} \
-c "PlenaryBustedDirectory ${TESTS_DIR} { minimal_init = '${TESTS_INIT}' }"
74 changes: 59 additions & 15 deletions lua/hawtkeys/init.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,69 @@
local M = {}

---@alias SupportedKeyboardLayouts "qwerty" | "dvorak"

---@class HawtKeyConfig
---@field leader string
---@field homerow number
---@field powerFingers number[]
---@field keyboardLayout SupportedKeyboardLayouts
---@field customMaps { [string] : TSKeyMapArgs | WhichKeyMapargs } | nil

---@class HawtKeyPartialConfig
---@field leader string | nil
---@field homerow number | nil
---@field powerFingers number[] | nil
---@field keyboardLayout SupportedKeyboardLayouts | nil
---@field customMaps { [string] : TSKeyMapArgs | WhichKeyMapargs } | nil
---

---@type { [string] : TSKeyMapArgs | WhichKeyMapargs }---

M._defaultSet = {
tris203 marked this conversation as resolved.
Show resolved Hide resolved
["vim.keymap.set"] = {
modeIndex = 1,
lhsIndex = 2,
rhsIndex = 3,
optsIndex = 4,
method = "dot_index_expression",
}, --method 1
["vim.api.nvim_set_keymap"] = {
modeIndex = 1,
lhsIndex = 2,
rhsIndex = 3,
optsIndex = 4,
method = "dot_index_expression",
}, --method 2
["whichkey.register"] = {
method = "which_key",
}, -- method 6
}

---@param config HawtKeyPartialConfig
function M.setup(config)
config = config or {}
M.leader = config.leader or " "
M.homerow = config.homerow or 2
M.powerFingers = config.powerFingers or { 2, 3, 6, 7 }
M.keyboardLayout = config.keyboardLayout or "qwerty"
vim.api.nvim_create_user_command(
"Hawtkeys",
"lua require('hawtkeys.ui').show()",
{}
)
vim.api.nvim_create_user_command(
"HawtkeysAll",
"lua require('hawtkeys.ui').show_all()",
{}
)
vim.api.nvim_create_user_command(
"HawtkeysDupes",
"lua require('hawtkeys.ui').show_dupes()",
{}
)
M.keyMapSet =
vim.tbl_extend("force", M._defaultSet, config.customMaps or {})
end

vim.api.nvim_create_user_command(
"Hawtkeys",
"lua require('hawtkeys.ui').show()",
{}
)
vim.api.nvim_create_user_command(
tris203 marked this conversation as resolved.
Show resolved Hide resolved
"HawtkeysAll",
"lua require('hawtkeys.ui').show_all()",
{}
)
vim.api.nvim_create_user_command(
"HawtkeysDupes",
"lua require('hawtkeys.ui').show_dupes()",
{}
)

return M
51 changes: 51 additions & 0 deletions lua/hawtkeys/tests/set_maps.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
vim.api.nvim_set_keymap(
"n",
"<leader>1",
':lua print("1 pressed")<CR>',
{ noremap = true, silent = true }
)
vim.keymap.set(
"n",
"<leader>2",
':lua print("2 pressed")<CR>',
{ noremap = true, silent = true }
)

local normalMap = function(lhs, rhs)
vim.api.nvim_set_keymap("n", lhs, rhs, { noremap = true, silent = true })
end
normalMap("<leader>3", ':lua print("3 pressed")<CR>')

local shortIndex = vim.api

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

local shortFunc = vim.api.nvim_set_keymap

shortFunc(
"n",
"<leader>5",
':lua print("5 pressed")<CR>',
{ noremap = true, silent = true }
)

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>8", ":lua print('8 pressed" },
},
}
5 changes: 5 additions & 0 deletions lua/hawtkeys/tests/test_ts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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()
Loading
Loading