aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorGiuseppe Gadola <giusgadola@gmail.com>2023-02-14 17:18:20 +0100
committerGiuseppe Gadola <giusgadola@gmail.com>2023-02-14 19:17:20 +0100
commit5e82cc8d69122b35b9b235ffa2a1015260627a19 (patch)
treee23c3113bfc2b507c0603b4ab0e0ab8b651fd20f /lua
parentrefactor(commands): get available pets one time (diff)
feat(commands): autocomplete for PetsKill
Diffstat (limited to 'lua')
-rw-r--r--lua/pets/commands.lua15
1 files changed, 12 insertions, 3 deletions
diff --git a/lua/pets/commands.lua b/lua/pets/commands.lua
index 87b7318..d9c6745 100644
--- a/lua/pets/commands.lua
+++ b/lua/pets/commands.lua
@@ -16,7 +16,7 @@ vim.api.nvim_create_user_command("PetsNew", function(input)
pets.create_pet(input.args, pet, style)
end, { nargs = 1 })
-local function autocomplete(_, cmdline)
+local function autocomplete_petsnew(_, cmdline)
local matches = {}
local words = vim.split(cmdline, " ", { trimempty = true })
@@ -46,7 +46,7 @@ vim.api.nvim_create_user_command("PetsNewCustom", function(input)
end
local type, style, name = args[1], args[2], args[3]
pets.create_pet(name, type, style)
-end, { nargs = 1, complete = autocomplete })
+end, { nargs = 1, complete = autocomplete_petsnew })
vim.api.nvim_create_user_command("PetsKillAll", function()
pets.kill_all()
@@ -54,7 +54,16 @@ end, {})
vim.api.nvim_create_user_command("PetsKill", function(input)
pets.kill_pet(input.args)
-end, { nargs = 1 })
+end, {
+ nargs = 1,
+ complete = function()
+ local matches = {}
+ for k, _ in pairs(pets.pets) do
+ table.insert(matches, k)
+ end
+ return matches
+ end,
+})
vim.api.nvim_create_user_command("PetsList", function()
pets.list()