Skip to content

Commit 05a740f

Browse files
authored
use user input to filter completion results (#372)
1 parent 9f4ef68 commit 05a740f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lua/render-markdown/command.lua

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,30 @@ M.name = 'RenderMarkdown'
99
---@private
1010
M.plugin = 'render-markdown.nvim'
1111

12+
local starts_with = function(str, start)
13+
return str:sub(1, #start) == start
14+
end
15+
16+
local get_matching_values = function(value, potential_values)
17+
local matching_values = {}
18+
for _, potential_value in ipairs(potential_values) do
19+
if starts_with(potential_value, value) then
20+
table.insert(matching_values, potential_value)
21+
end
22+
end
23+
return matching_values
24+
end
25+
1226
---Should only be called from plugin directory
1327
function M.setup()
1428
vim.api.nvim_create_user_command(M.name, M.command, {
1529
nargs = '*',
1630
desc = M.plugin .. ' commands',
17-
complete = function(_, cmdline)
31+
complete = function(ArgLead, cmdline)
1832
if cmdline:find(M.name .. '%s+%S+%s+.*') then
1933
return {}
2034
elseif cmdline:find(M.name .. '%s+') then
21-
return vim.tbl_keys(api)
35+
return get_matching_values(ArgLead, vim.tbl_keys(api))
2236
else
2337
return {}
2438
end

0 commit comments

Comments
 (0)