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: Windows Support #68

Merged
merged 33 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3e5bbc0
ci:Cross platform tests
tris203 Jan 2, 2024
c3cde54
ci:Cross platform tests
tris203 Jan 2, 2024
261d555
ci:Cross platform tests
tris203 Jan 2, 2024
2dc27a1
fix(ci): us os_tmpdir intead of /tmp
willothy Jan 2, 2024
815bbb4
ci: longer timeout
tris203 Jan 2, 2024
65da0f8
ci: short win path
tris203 Jan 3, 2024
7434bf8
tests: mini fork
tris203 Jan 3, 2024
c8e574b
remove mini.test
tris203 Jan 3, 2024
e882b5f
add wipeout
tris203 Jan 3, 2024
7f66ec1
Merge branch 'main' into crossplatform_tests
tris203 Jan 4, 2024
366075e
Merge branch 'main' into crossplatform_tests
tris203 Jan 6, 2024
9452728
tests: e2e tests
tris203 Jan 6, 2024
fd24f16
chore: style
tris203 Jan 6, 2024
99750ac
ci: make dir
tris203 Jan 6, 2024
990dbd5
ci: fix?
tris203 Jan 6, 2024
597f7fd
ci mkdir
tris203 Jan 6, 2024
365d15a
better?
tris203 Jan 6, 2024
0a7f8af
file check
tris203 Jan 6, 2024
aa13916
debug
tris203 Jan 6, 2024
314a613
feat(windows support): change path filtering
tris203 Jan 6, 2024
e0377f5
drop filter
tris203 Jan 6, 2024
620adbb
chore:style
tris203 Jan 6, 2024
fee19be
path fix?
tris203 Jan 6, 2024
30eaee0
debug
tris203 Jan 6, 2024
0162ac8
path sep
tris203 Jan 6, 2024
84950d5
chore: style
tris203 Jan 6, 2024
f9bf525
chore: cleanup
tris203 Jan 6, 2024
97eaeb1
cleanup
tris203 Jan 6, 2024
46dad22
code review
tris203 Jan 7, 2024
030384d
chore: style
tris203 Jan 7, 2024
4caae32
Merge branch 'main' into crossplatform_tests
tris203 Jan 12, 2024
1fe7bae
Merge branch 'main' into crossplatform_tests
tris203 Jan 15, 2024
d67b3bd
Merge branch 'main' into crossplatform_tests
tris203 Mar 29, 2024
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
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ on:

jobs:
test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os}}
strategy:
matrix:
nvim-versions: ['stable', 'nightly']
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false
name: Plenary Tests
steps:
- name: checkout
Expand Down
3 changes: 2 additions & 1 deletion .luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"diagnostics.globals": [
"describe",
"it",
"before_each"
"before_each",
"after_each"
]
}
27 changes: 14 additions & 13 deletions lua/hawtkeys/ts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,6 @@ local function get_keymaps_from_vim()
return vimKeymaps
end

---@return string[]
local function get_runtime_path()
return vim.api.nvim_list_runtime_paths()
end

---@return HawtkeysKeyMapData[]
function M.get_all_keymaps()
local returnKeymaps
Expand All @@ -469,17 +464,23 @@ function M.get_all_keymaps()
end
end
else
local paths = get_runtime_path()
local paths = vim.fn.stdpath("config")
tris203 marked this conversation as resolved.
Show resolved Hide resolved
if not paths then
return {}
end
if type(paths) == "string" then
paths = { paths }
end
for _, path in ipairs(paths) do
if string.match(path, "%.config") then
local files = find_files(path)
for _, file in ipairs(files) do
local file_keymaps = find_maps_in_file(file)
for _, keymap in ipairs(file_keymaps) do
table.insert(keymaps, keymap)
end
-- if string.match(path, "%.config") then
local files = find_files(path)
for _, file in ipairs(files) do
local file_keymaps = find_maps_in_file(file)
for _, keymap in ipairs(file_keymaps) do
table.insert(keymaps, keymap)
end
end
-- end
end
end

Expand Down
91 changes: 91 additions & 0 deletions tests/hawtkeys/e2e_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---@diagnostic disable-next-line: undefined-field
local eq = assert.are.same
local ts = require("hawtkeys.ts")
local path = require("plenary.path")

local sep = (function()
if jit then
local os = string.lower(jit.os)
if os ~= "windows" then
return "/"
else
return "\\"
end
else
return package.config:sub(1, 1)
end
end)()

local function copy_configs_to_stdpath_config()
local config_dir = vim.fn.stdpath("config")
vim.fn.mkdir(config_dir, "p")
vim.fn.writefile(
vim.fn.readfile("tests/hawtkeys/example_configs/e2e_config.lua"),
config_dir .. "/e2e_config.lua"
)
end

describe("file searching", function()
before_each(function()
copy_configs_to_stdpath_config()
require("hawtkeys").setup({})
end)

it("can detect a Vim Default Keymap", function()
local notMatch = 0
local keymaps = ts.get_all_keymaps()
for _, v in ipairs(keymaps) do
if
vim.deep_equal(v, {
from_file = "Vim Defaults",
lhs = "Y",
mode = "n",
rhs = "y$",
})
then
eq(v, {
from_file = "Vim Defaults",
lhs = "Y",
mode = "n",
rhs = "y$",
})
else
notMatch = notMatch + 1
end
end
eq(vim.tbl_count(keymaps), notMatch + 1)
end)

it("can detect a keymap from a file", function()
local config_file =
path:new(vim.fn.stdpath("config") .. sep .. "e2e_config.lua")
eq(true, config_file:is_file())
local notMatch = 0
local keymaps = ts.get_all_keymaps()

for _, v in ipairs(keymaps) do
if
vim.deep_equal(v, {
from_file = config_file:absolute(),
lhs = "<leader>example",
mode = "n",
rhs = "<cmd>echo 'Example'<cr>",
})
then
eq(v, {
from_file = config_file:absolute(),
lhs = "<leader>example",
mode = "n",
rhs = "<cmd>echo 'Example'<cr>",
})
else
notMatch = notMatch + 1
end
end
eq(vim.tbl_count(keymaps), notMatch + 1)
end)

it("should find a file in stdpath('config')", function()
eq(true, true)
end)
end)
1 change: 1 addition & 0 deletions tests/hawtkeys/example_configs/e2e_config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vim.api.nvim_set_keymap("n", "<leader>example", "<cmd>echo 'Example'<cr>", {})
101 changes: 53 additions & 48 deletions tests/hawtkeys/ui_spec.lua
Original file line number Diff line number Diff line change
@@ -1,63 +1,64 @@
---@diagnostic disable-next-line: undefined-field
local eq = assert.are.same

local MiniTest = require("mini.test")

---TODO: add search functionality tests (willothy)

describe("ui", function()
local child = MiniTest.new_child_neovim()
local SearchBuf, SearchWin, ResultBuf, ResultWin, Namespace, prompt_extmark

before_each(function()
child.restart({ "-u", "tests/minimal_init.lua" })
child.lua([[require("hawtkeys").setup({})]])
require("plenary.reload").reload_module("hawtkeys")
vim.cmd([[bufdo! bwipeout]])
require("hawtkeys").setup({})
end)

describe("search", function()
before_each(function()
child.lua([[require("hawtkeys.ui").show()]])
require("plenary.reload").reload_module("hawtkeys")
vim.cmd([[bufdo! bwipeout]])
require("hawtkeys").setup({})
vim.cmd([[lua require("hawtkeys.ui").show()]])
SearchBuf, SearchWin, ResultBuf, ResultWin, Namespace, prompt_extmark =
tris203 marked this conversation as resolved.
Show resolved Hide resolved
unpack(child.lua([[
local ui = require("hawtkeys.ui")
return {
ui.SearchBuf,
ui.SearchWin,
ui.ResultBuf,
ui.ResultWin,
ui.Namespace,
ui.prompt_extmark
}
]]))
unpack((function()
local ui = require("hawtkeys.ui")
return {
ui.SearchBuf,
ui.SearchWin,
ui.ResultBuf,
ui.ResultWin,
ui.Namespace,
ui.prompt_extmark,
}
end)())
tris203 marked this conversation as resolved.
Show resolved Hide resolved
end)

it("should show the search UI", function()
assert(child.api.nvim_buf_is_valid(SearchBuf))
assert(child.api.nvim_win_is_valid(SearchWin))
assert(vim.api.nvim_buf_is_valid(SearchBuf))
assert(vim.api.nvim_win_is_valid(SearchWin))

assert(child.api.nvim_buf_is_valid(ResultBuf))
assert(child.api.nvim_win_is_valid(ResultWin))
assert(vim.api.nvim_buf_is_valid(ResultBuf))
assert(vim.api.nvim_win_is_valid(ResultWin))

eq(SearchBuf, child.api.nvim_get_current_buf())
eq(SearchWin, child.api.nvim_get_current_win())
eq(SearchBuf, vim.api.nvim_get_current_buf())
eq(SearchWin, vim.api.nvim_get_current_win())

local win_config = child.api.nvim_win_get_config(SearchWin)
local win_config = vim.api.nvim_win_get_config(SearchWin)
eq("editor", win_config.relative)
end)
--TODO: This doesnt work since removing the dependency on mini.test
--[[ it("starts in insert mode", function()
assert(vim.api.nvim_buf_is_valid(SearchBuf))
assert(vim.api.nvim_win_is_valid(SearchWin))

it("starts in insert mode", function()
assert(child.api.nvim_buf_is_valid(SearchBuf))
assert(child.api.nvim_win_is_valid(SearchWin))

eq(child.api.nvim_get_current_win(), SearchWin)
eq("i", child.api.nvim_get_mode().mode)
eq(vim.api.nvim_get_current_win(), SearchWin)
eq("i", vim.api.nvim_get_mode().mode)
end)

]]
it("should show the hint extmark", function()
assert(SearchBuf)
assert(prompt_extmark)
assert(Namespace)
local extmark_info = child.api.nvim_buf_get_extmark_by_id(
local extmark_info = vim.api.nvim_buf_get_extmark_by_id(
SearchBuf,
Namespace,
prompt_extmark,
Expand All @@ -70,50 +71,54 @@ describe("ui", function()

describe("all", function()
before_each(function()
child.lua([[require("hawtkeys.ui").show_all()]])
ResultBuf, ResultWin, Namespace = unpack(child.lua([[
require("plenary.reload").reload_module("hawtkeys")
vim.cmd([[bufdo! bwipeout]])
require("hawtkeys").setup({})
vim.cmd([[lua require("hawtkeys.ui").show_all()]])
ResultBuf, ResultWin, Namespace = unpack((function()
local ui = require("hawtkeys.ui")
return {
ui.ResultBuf,
ui.ResultWin,
ui.Namespace,
}
tris203 marked this conversation as resolved.
Show resolved Hide resolved
]]))
end)())
tris203 marked this conversation as resolved.
Show resolved Hide resolved
end)

it("should show the all UI", function()
assert(child.api.nvim_buf_is_valid(ResultBuf))
assert(child.api.nvim_win_is_valid(ResultWin))
print(vim.inspect(ResultBuf))
assert(vim.api.nvim_buf_is_valid(ResultBuf))
assert(vim.api.nvim_win_is_valid(ResultWin))

eq(child.api.nvim_get_current_buf(), ResultBuf)
eq(child.api.nvim_get_current_win(), ResultWin)
eq(vim.api.nvim_get_current_buf(), ResultBuf)
eq(vim.api.nvim_get_current_win(), ResultWin)

local win_config = child.api.nvim_win_get_config(ResultWin)
local win_config = vim.api.nvim_win_get_config(ResultWin)
eq(win_config.relative, "editor")
end)
end)

describe("dupes", function()
before_each(function()
child.lua([[require("hawtkeys.ui").show_dupes()]])
ResultBuf, ResultWin, Namespace = unpack(child.lua([[
vim.cmd([[lua require("hawtkeys.ui").show_dupes()]])
ResultBuf, ResultWin, Namespace = unpack((function()
local ui = require("hawtkeys.ui")
return {
ui.ResultBuf,
ui.ResultWin,
ui.Namespace,
}
tris203 marked this conversation as resolved.
Show resolved Hide resolved
]]))
end)())
tris203 marked this conversation as resolved.
Show resolved Hide resolved
end)

it("should show the duplicates UI", function()
assert(child.api.nvim_buf_is_valid(ResultBuf))
assert(child.api.nvim_win_is_valid(ResultWin))
assert(vim.api.nvim_buf_is_valid(ResultBuf))
assert(vim.api.nvim_win_is_valid(ResultWin))

eq(child.api.nvim_get_current_buf(), ResultBuf)
eq(child.api.nvim_get_current_win(), ResultWin)
eq(vim.api.nvim_get_current_buf(), ResultBuf)
eq(vim.api.nvim_get_current_win(), ResultWin)

local win_config = child.api.nvim_win_get_config(ResultWin)
local win_config = vim.api.nvim_win_get_config(ResultWin)
eq(win_config.relative, "editor")
end)
end)
Expand Down
26 changes: 11 additions & 15 deletions tests/minimal_init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
local M = {}

local function tempdir(plugin)
if jit.os == "Windows" then
return "D:\\tmp\\" .. plugin
end
return vim.loop.os_tmpdir() .. "/" .. plugin
end

function M.loadLazy()
local lazy_dir = os.getenv("LAZY_DIR") or "/tmp/lazy.nvim"
local lazy_dir = os.getenv("LAZY_DIR") or tempdir("lazy.nvim")
if vim.fn.isdirectory(lazy_dir) == 0 then
vim.fn.system({
"git",
Expand All @@ -17,7 +24,7 @@ function M.loadLazy()
end

function M.loadWhichKey()
local whichkey_dir = os.getenv("WHICHKEY_DIR") or "/tmp/which-key.nvim"
local whichkey_dir = os.getenv("WHICHKEY_DIR") or tempdir("which-key.nvim")
if vim.fn.isdirectory(whichkey_dir) == 0 then
vim.fn.system({
"git",
Expand All @@ -32,9 +39,8 @@ function M.loadWhichKey()
require("which-key").setup({})
end

local plenary_dir = os.getenv("PLENARY_DIR") or "/tmp/plenary.nvim"
local treesitter_dir = os.getenv("TREESITTER_DIR") or "/tmp/nvim-treesitter"
local mini_dir = os.getenv("MINI_DIR") or "/tmp/mini-test"
local plenary_dir = os.getenv("PLENARY_DIR") or tempdir("plenary.nvim")
local treesitter_dir = os.getenv("TREESITTER_DIR") or tempdir("nvim-treesitter")
if vim.fn.isdirectory(plenary_dir) == 0 then
vim.fn.system({
"git",
Expand All @@ -51,20 +57,10 @@ if vim.fn.isdirectory(treesitter_dir) == 0 then
treesitter_dir,
})
end
if vim.fn.isdirectory(mini_dir) == 0 then
vim.fn.system({
"git",
"clone",
"https://github.com/echasnovski/mini.test",
mini_dir,
})
end
vim.opt.rtp:append(".")
vim.opt.rtp:append(plenary_dir)
vim.opt.rtp:append(treesitter_dir)
vim.opt.rtp:append(mini_dir)
require("plenary.busted")
require("mini.test").setup()

vim.cmd("runtime plugin/plenary.vim")
vim.cmd("runtime plugin/treesitter.vim")
Expand Down
Loading