Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Trigger path completion only after typing path separator #373

Open
noib3 opened this issue Jun 5, 2021 · 6 comments
Open

Trigger path completion only after typing path separator #373

noib3 opened this issue Jun 5, 2021 · 6 comments

Comments

@noib3
Copy link

noib3 commented Jun 5, 2021

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.

@gpanders
Copy link

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).

@ranjithshegde
Copy link
Contributor

@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': ['/']},
    \   }
    \}

@noib3
Copy link
Author

noib3 commented Jul 6, 2021

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.

@ranjithshegde
Copy link
Contributor

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

@noib3
Copy link
Author

noib3 commented Jul 6, 2021

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.

@ranjithshegde
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants