diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..a5f3ce3 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,26 @@ +name: Format + +on: [push, pull_request] + +jobs: + format: + name: Stylua + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: date +%W > weekly + + - name: Restore cache + id: cache + uses: actions/cache@v2 + with: + path: | + ~/.cargo/bin + key: ${{ runner.os }}-cargo-${{ hashFiles('weekly') }} + + - name: Install + if: steps.cache.outputs.cache-hit != 'true' + run: cargo install stylua + + - name: Format + run: stylua --check lua/ --config-path=.stylua.toml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..46759d5 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,18 @@ +name: Lint + +on: [push, pull_request] + +jobs: + lint: + name: Luacheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup + run: | + sudo apt-get update + sudo apt-get install luarocks + sudo luarocks install luacheck + + - name: Lint + run: luacheck lua/ --globals vim diff --git a/lua/hawtkeys/init.lua b/lua/hawtkeys/init.lua index bd7cad7..429bdf4 100644 --- a/lua/hawtkeys/init.lua +++ b/lua/hawtkeys/init.lua @@ -1,4 +1,4 @@ -M = {} +local M = {} function M.setup(config) M.leader = config.leader or " " M.homerow = config.homerow or 2 diff --git a/lua/hawtkeys/keyboards.lua b/lua/hawtkeys/keyboards.lua index 5f868f6..3c3debb 100644 --- a/lua/hawtkeys/keyboards.lua +++ b/lua/hawtkeys/keyboards.lua @@ -1,4 +1,4 @@ -M = {} +local M = {} -- TODO: Make this dynamic, loading from the keyboards directory M.qwerty = require("hawtkeys.keyboards.qwerty").layout diff --git a/lua/hawtkeys/score.lua b/lua/hawtkeys/score.lua index 0716b23..bf153c3 100644 --- a/lua/hawtkeys/score.lua +++ b/lua/hawtkeys/score.lua @@ -3,6 +3,32 @@ local keyboardLayouts = require("hawtkeys.keyboards") local tsSearch = require("hawtkeys.ts") local utils = require("hawtkeys.utils") +---@param key1 string +---@param key2 string +---@param str string +---@return integer +local function Mnemonic_score(key1, key2, str) + -- returns a bonus point if the keys are the first letter of a word + local words = {} + for word in str:gmatch("%S+") do + table.insert(words, word) + end + + local bonus = 0 + for _, word in ipairs(words) do + if word:sub(1, 1):lower() == key1 or word:sub(1, 1):lower() == key2 then + bonus = bonus + 1 + end + end + + --if key1 equals first letter of string then bonus = bonus + 1 + if str:sub(1, 1):lower() == key1 then + bonus = bonus + 1 + end + + return bonus +end + ---@param key1 string ---@param key2 string ---@param str string @@ -60,32 +86,6 @@ local function key_score(key1, key2, str, layout) end end ----@param key1 string ----@param key2 string ----@param str string ----@return integer -function Mnemonic_score(key1, key2, str) - -- returns a bonus point if the keys are the first letter of a word - local words = {} - for word in str:gmatch("%S+") do - table.insert(words, word) - end - - local bonus = 0 - for _, word in ipairs(words) do - if word:sub(1, 1):lower() == key1 or word:sub(1, 1):lower() == key2 then - bonus = bonus + 1 - end - end - - --if key1 equals first letter of string then bonus = bonus + 1 - if str:sub(1, 1):lower() == key1 then - bonus = bonus + 1 - end - - return bonus -end - -- Function to generate all possible two-character combinations ---@param str string ---@return table diff --git a/lua/hawtkeys/show_all.lua b/lua/hawtkeys/show_all.lua index 788e65d..bee6bed 100644 --- a/lua/hawtkeys/show_all.lua +++ b/lua/hawtkeys/show_all.lua @@ -1,4 +1,4 @@ -M = {} +local M = {} local tsSearch = require("hawtkeys.ts") ---@return table diff --git a/lua/hawtkeys/ui.lua b/lua/hawtkeys/ui.lua index e292c72..4f0ce90 100644 --- a/lua/hawtkeys/ui.lua +++ b/lua/hawtkeys/ui.lua @@ -1,6 +1,10 @@ -M = {} -Hawtkeys = require("hawtkeys.score") -ShowAll = require("hawtkeys.show_all") +local M = {} +local Hawtkeys = require("hawtkeys.score") +local ShowAll = require("hawtkeys.show_all") +local ResultWin = 0 +local ResultBuf = 0 +local SearchWin = 0 + M.search = function(text) local returnText = Hawtkeys.ScoreTable(text) vim.api.nvim_buf_set_lines(ResultBuf, 0, -1, false, returnText) diff --git a/lua/hawtkeys/utils.lua b/lua/hawtkeys/utils.lua index 792cebe..9697682 100644 --- a/lua/hawtkeys/utils.lua +++ b/lua/hawtkeys/utils.lua @@ -1,4 +1,4 @@ -M = {} +local M = {} --- @param table table --- @param value string