From fd8859e520eadd1842e9b70511d9389900092eb6 Mon Sep 17 00:00:00 2001 From: Rainer Borene Date: Sat, 11 Jan 2025 14:30:12 -0300 Subject: [PATCH] fix(cmdline): make completion work for and s: viml function (#925) * fix(cmdline): make completion work for and s: viml function * docs: add todo about simplifying cmdline completions --------- Co-authored-by: Liam Dyer --- lua/blink/cmp/sources/cmdline/init.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lua/blink/cmp/sources/cmdline/init.lua b/lua/blink/cmp/sources/cmdline/init.lua index 5ff5e11a..9ad9d5d9 100644 --- a/lua/blink/cmp/sources/cmdline/init.lua +++ b/lua/blink/cmp/sources/cmdline/init.lua @@ -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 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, '') + 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