Skip to content

Commit

Permalink
chore: ci (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 authored Dec 16, 2023
1 parent 693e825 commit 26b1435
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 33 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lua/hawtkeys/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
M = {}
local M = {}
function M.setup(config)
M.leader = config.leader or " "
M.homerow = config.homerow or 2
Expand Down
2 changes: 1 addition & 1 deletion lua/hawtkeys/keyboards.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
M = {}
local M = {}
-- TODO: Make this dynamic, loading from the keyboards directory
M.qwerty = require("hawtkeys.keyboards.qwerty").layout

Expand Down
52 changes: 26 additions & 26 deletions lua/hawtkeys/score.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/hawtkeys/show_all.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
M = {}
local M = {}
local tsSearch = require("hawtkeys.ts")

---@return table
Expand Down
10 changes: 7 additions & 3 deletions lua/hawtkeys/ui.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lua/hawtkeys/utils.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
M = {}
local M = {}

--- @param table table
--- @param value string
Expand Down

0 comments on commit 26b1435

Please sign in to comment.