Skip to content

Commit

Permalink
fix: command complete issues (#27)
Browse files Browse the repository at this point in the history
Co-authored-by: eph <[email protected]>
  • Loading branch information
epheien and eph authored Jul 17, 2024
1 parent b394bc1 commit 97c9d82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 13 additions & 3 deletions lua/pckr/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ local log = require('pckr.log')

local M = {}

--- @param lead string
--- @return string[]
local function command_complete()
local function command_complete(lead)
local actions = require('pckr.actions')
return vim.tbl_keys(actions)
local completion_list = vim.tbl_filter(
--- @param name string
--- @return boolean
function(name)
return vim.startswith(name, lead)
end,
vim.tbl_keys(actions)
)
table.sort(completion_list)
return completion_list
end

-- Completion user plugins
Expand Down Expand Up @@ -36,7 +46,7 @@ function M.complete(arglead, line)

local matches = {}
if n == 2 then
matches = command_complete()
matches = command_complete(arglead)
elseif n > 2 then
matches = plugin_complete(arglead)
end
Expand Down
4 changes: 2 additions & 2 deletions lua/pckr/loader/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ return function(cmd)
end, {
bang = true,
nargs = '*',
complete = function()
complete = function(arg_lead, cmd_line, cursor_pos)
vim.api.nvim_del_user_command(cmd)
loader()
return vim.fn.getcompletion(cmd .. ' ', 'cmdline')
return vim.fn.getcompletion(cmd_line, 'cmdline')
end,
})
end
Expand Down

0 comments on commit 97c9d82

Please sign in to comment.