blink.cmp icon indicating copy to clipboard operation
blink.cmp copied to clipboard

Cmdline completion does not provide arg lead input to custom command completion

Open kristijanhusak opened this issue 1 year ago • 2 comments

Make sure you have done the following

  • [X] I have updated to the latest version of blink.cmp
  • [X] I have read the README

Bug Description

New cmdline completion does not provide "arg_lead" to the custom command completion. Steps to reproduce:

  1. Open configuration below: nvim -u mininit.lua
  2. Type :Find something
  3. Type :messages, you will see only ARG LEAD

Expected: To see ARG LEAD something in :messages.

Relevant configuration

vim.env.LAZY_STDPATH = '.repro'
load(vim.fn.system('curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua'))()

require('lazy.minit').repro({
  spec = {
    {
      'Saghen/blink.cmp',
      version = '0.*',
      opts = {},
    },
  },
})

vim.api.nvim_create_user_command('Find', function() end, {
  force = true,
  nargs = '?',
  complete = function(arg_lead)
    print('ARG LEAD', arg_lead)
  end,
})

neovim version

0.10.2

blink.cmp version: branch, tag, or commit

0.8.0

kristijanhusak avatar Dec 21 '24 08:12 kristijanhusak

This was done intentionally to prevent the complete functions from filtering out items. If you type :Find foo=bar, it'll pass foo= as the arg lead. What's your use case for having the whole arg lead though?

saghen avatar Dec 21 '24 20:12 saghen

I have a custom :Find command to use as a fuzzy finder (https://github.com/kristijanhusak/neovim-config/blob/master/nvim/after/plugin/find.lua). I use ripgrep to filter down the results. If I return all results instead of slicing them on half, it works, so that part is more/less solved.

The bigger issue for me is autocompletion on input() function. In orgmode, there is an option to move a specific headline to another file. This opens up an input prompt, and allows autocompleting files where the headline should be moved. With cmdline enabled, it is not working. If I set cmdline = {'cmdline'}, it autocompletes, but not what I set in the complete function. I'm not sure if you are an orgmode user, so here's a simple example in vimscript:

function! DoAutocomplete(A,L,P) abort
  return ['one', 'two', 'three']
endfunction

call input('test: ', '', 'customlist,DoAutocomplete')

With cmdline disabled, sourcing this file and pressing tab autocompletes "one,two,three". With cmdline with default value, or set to {'cmdline'}, it does not return anything.

kristijanhusak avatar Dec 22 '24 15:12 kristijanhusak

Thanks for the fix. This fixes the issue with input, but it breaks the regular completion for commands. For example, if you use telescope, try doing :Telescope f. You get an error:

Error while fetching completions: Vim:E475: Invalid argument:

That's because getcmdcompltype() returns empty string in that case.

kristijanhusak avatar Dec 31 '24 20:12 kristijanhusak

Fixed on main, thanks!

saghen avatar Dec 31 '24 20:12 saghen

I'm still getting the following error on version 0.9.0 when I type commands such as :Telescope f

Error while fetching completions: Vim:E5108: Error executing Lua function: attempt to call a number value

justicenyaga avatar Jan 02 '25 18:01 justicenyaga