Skip to content

Commit

Permalink
fix(cmdline): make completion work for <sid> and s: viml function (#925)
Browse files Browse the repository at this point in the history
* fix(cmdline): make completion work for <sid> and s: viml function

* docs: add todo about simplifying cmdline completions

---------

Co-authored-by: Liam Dyer <[email protected]>
  • Loading branch information
rainerborene and Saghen authored Jan 11, 2025
1 parent 0fe891f commit fd8859e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lua/blink/cmp/sources/cmdline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ function cmdline:get_completions(context, callback)
end

local completions = {}
local completion_type = vim.fn.getcmdcompltype()
local completion_args = vim.split(vim.fn.getcmdcompltype(), ',', { plain = true })
local completion_type = completion_args[1]
local completion_func = completion_args[2]

-- Handle custom completions explicitly, since otherwise they won't work in input() mode (getcmdtype() == '@')
if vim.startswith(completion_type, 'custom,') or vim.startswith(completion_type, 'customlist,') then
local fun = completion_type:gsub('custom,', ''):gsub('customlist,', '')
completions = vim.fn.call(fun, { current_arg_prefix, vim.fn.getcmdline(), vim.fn.getcmdpos() })
-- TODO: however, we cannot handle s: and <sid> completions. is there a better solution here where we can get
-- completions in input() mode without calling ourselves?
if
vim.startswith(completion_type, 'custom')
and not vim.startswith(completion_func, 's:')
and not vim.startswith(completion_func, '<sid>')
then
completions = vim.fn.call(completion_func, { current_arg_prefix, vim.fn.getcmdline(), vim.fn.getcmdpos() })
-- `custom,` type returns a string, delimited by newlines
if type(completions) == 'string' then completions = vim.split(completions, '\n') end
else
Expand Down

0 comments on commit fd8859e

Please sign in to comment.