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: one usercommand + autocomplete #63

Merged
merged 4 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 16 additions & 5 deletions lua/hawtkeys/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,22 @@ function M.setup(config)
group = auGroup,
})

vim.api.nvim_create_user_command(
"Hawtkeys",
"lua require('hawtkeys.ui').show()",
{}
)
vim.api.nvim_create_user_command("Hawtkeys", function(args)
if args.fargs[#args.fargs]:lower() == "all" then
require("hawtkeys.ui").show_all()
elseif args.fargs[#args.fargs]:lower() == "dupes" then
require("hawtkeys.ui").show_dupes()
tris203 marked this conversation as resolved.
Show resolved Hide resolved
else
require("hawtkeys.ui").show()
end
end, {
desc = "Show Hawtkeys",
nargs = "?",
complete = function()
return { "all", "dupes", "search" }
tris203 marked this conversation as resolved.
Show resolved Hide resolved
end,
})

vim.api.nvim_create_user_command(
"HawtkeysAll",
"lua require('hawtkeys.ui').show_all()",
Expand Down
25 changes: 13 additions & 12 deletions tests/hawtkeys/init_spec.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
local hawtkeys = require("hawtkeys")
---@diagnostic disable-next-line: undefined-field
local eq = assert.are.same
---@diagnostic disable-next-line: undefined-field
local falsy = assert.falsy

local userCommands = {
["Hawtkeys"] = "lua require('hawtkeys.ui').show()",
["HawtkeysAll"] = "lua require('hawtkeys.ui').show_all()",
["HawtkeysDupes"] = "lua require('hawtkeys.ui').show_dupes()",
["Hawtkeys"] = { definition = "Show Hawtkeys", nargs = "?" },
["HawtkeysAll"] = {
definition = "lua require('hawtkeys.ui').show_all()",
nargs = "0",
},
["HawtkeysDupes"] = {
definition = "lua require('hawtkeys.ui').show_dupes()",
nargs = "0",
},
}

describe("set up function", function()
Expand Down Expand Up @@ -69,17 +74,13 @@ describe("set up function", function()
end)

it("User commands should be available after setup", function()
local commandspresetup = vim.api.nvim_get_commands({})
hawtkeys.setup({})

local commandsPostSetup = vim.api.nvim_get_commands({})
-- Check that the commands are not present before setup
for command, _ in ipairs(userCommands) do
falsy(commandspresetup[command])
end
-- Check that the commands are present after setup
for command, action in ipairs(userCommands) do
eq(action, commandsPostSetup[command].definition)
for command, action in pairs(userCommands) do
eq(action.definition, commandsPostSetup[command].definition)
eq(action.nargs, commandsPostSetup[command].nargs)
end
end)
end)
Loading