completion-nvim icon indicating copy to clipboard operation
completion-nvim copied to clipboard

Trigger path completion only after typing path separator

Open noib3 opened this issue 4 years ago • 6 comments

Is your feature request related to a problem? Please describe. Let's say I have a directory with a single foo.vim file inside it and I start editing it.

Having included 'path' in my default complete_items, if I type f I get foo.vim Path (file) as an autocompletion suggestion. I'd like to change this behaviour so that the autocompletion triggers only after typing /, so in this case if I wanted to autocomplete foo.vim I'd have to type ./.

Describe the solution you'd like Completions from Path sources are only triggered after typing the os's path separator.

noib3 avatar Jun 05 '21 18:06 noib3

Similarly, if a path separator is found completion should only offer path completion items (e.g. if I have /usr/local/ then I most likely don't want auto completion to suggest LSP symbols).

gpanders avatar Jun 28 '21 22:06 gpanders

@noib3 I am not sure if you are already aware of this, but you can set trigger character for each source like this

let g:completion_chain_complete_list = {
    \ 'default' : {
    \   'default': [
    \       {'complete_items': ['lsp']},
    \       {'complete_items': ['path'], 'triggered_only': ['/']},
    \   }
    \}

ranjithshegde avatar Jul 04 '21 08:07 ranjithshegde

I didn't know that, I just tried it and it works. However having two separate completion sources is not very ergonomic since it requires extra key presses to select the right source. I wish I could specify path sources to only be triggered after a / while still having a single completion menu with all the possible items.

noib3 avatar Jul 06 '21 16:07 noib3

You could play around with let g:completion_auto_change_source = 1 and changing the priorities of sources as necessary

ranjithshegde avatar Jul 06 '21 16:07 ranjithshegde

I tried that with the following setup (lua syntax):

local g = vim.g

g.completion_chain_complete_list = {
  default = {
    {complete_items = {'path'}, triggered_only = {'/'}},
    {complete_items = {'lsp'}},
  },
}

g.completion_auto_change_source = 1

I'd expect lsp completions to show up when I'm not typing a path, but I get the same exact behaviour that I get leaving g:completion_auto_change_source to zero.

noib3 avatar Jul 06 '21 19:07 noib3

the per source triggered_only is a new and not yet documented feature. Perhaps @haorenW1025 the author could help you further

ranjithshegde avatar Jul 07 '21 06:07 ranjithshegde