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 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 .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}' }"
43 changes: 43 additions & 0 deletions lua/hawtkeys/init.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,53 @@
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 }---

local _defaultSet = {
["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"
M.keyMapSet = vim.tbl_extend("force", _defaultSet, config.customMaps or {})

vim.api.nvim_create_user_command(
"Hawtkeys",
"lua require('hawtkeys.ui').show()",
Expand Down
Loading
Loading