lifepillar / vim-mucomplete

Chained completion that works the way you want!
MIT License
913 stars 18 forks source link

Complete after '.' and also add closing parenthesis #46

Closed JohnAppleSeed- closed 7 years ago

JohnAppleSeed- commented 7 years ago

For bug reports only, please provide the following details:


I have a couple of issues:

- I don't get an auto-popup until I type the second letter of a word, I would prefer to get a popup immediately after the first letter and also immediately after the `.` notation used for accessing objects. Is this possible to configure? Here is a gif: https://i.imgur.com/hXrZ1eY.gif (the first time I don't press tab and have to type two letters before the popup shows, the second time I just press tab after the `.` and it loads fine)

- I like that it inserts a parenthesis, but is there a way to make it insert a closing parenthesis and place your cursor in between them? Or a way to turn off the behavior of inserting a parenthesis?

I only tested it with golang and vim-go
lifepillar commented 7 years ago

I don't get an auto-popup until I type the second letter of a word

Please see :h g:mucomplete#trigger_auto_pattern. You may try to put this in your vimrc:

let g:mucomplete#trigger_auto_pattern = { 'default': '\%(\k\|\.\)$' }

or, if you want that pattern only for Go:

let g:mucomplete#trigger_auto_pattern = { 'go': '\%(\k\|\.\)$' }

The regular expression matches a keyword character (\k) or a dot (\.) just before the cursor.

I like that it inserts a parenthesis, but is there a way to make it insert a closing parenthesis and place your cursor in between them?

That behaviour is not controlled by µcomplete, but by the omni completion plugin you are using. To verify that, turn off autocompletion (:MUcompleteAutoOff), type some characters and try to complete with <c-x><c-o>.

JohnAppleSeed- commented 7 years ago

K thanks I can probably switch to this from ycm then.

JohnAppleSeed- commented 7 years ago

Now that trigger_auto_pattern has been removed how do I do this with the can_complete function?

I tried

let g:mucomplete#can_complete = { 'default': '\%(\k\|\.\)$' }

but I get the error:

Error detected while processing /home/zxcv/.vim/plugged/vim-mucomplete/autoload/mucomplete.vim:
line  137:                                                                                     
E712: Argument of extend() must be a List or Dictionary                                        

And I read the docs but I don't understand how to do this.

lifepillar commented 7 years ago

Auto patterns now are completion-type specific. So, for example:

let g:mucomplete#can_complete = {
  \ 'default': {
  \    'omni': { t -> strlen(&l:omnifunc) > 0 && t =~# '\%(\k\|\.\)$' }
  \    }
  \  }

Edit: fixed typo

lifepillar commented 7 years ago

Admittedly, although the new way is most flexible, for some users it may appear too cumbersome compared to the previous one. If that is the case for you, please open a new issue, so I will think of a better solution.

JohnAppleSeed- commented 7 years ago

When I try your solution I get the error:

E121: Undefined variable: t
E15: Invalid expression: { 'default': { 'omni': t -> strlen(&l:omnifunc) > 0 && t =~# '\%(\k|.)$' } }

lifepillar commented 7 years ago

Does your Vim support lambdas? If :echo has('lambda') returns 0, you have to use standard functions, e.g.:

    function CanOmnicomplete(t)
      return strlen(&l:omnifunc) > 0 && a:t =~# '\%(\k\|\.\)$'
    endf

    let g:mucomplete#can_complete = {
      \ 'default': {
      \    'omni': function('CanOmnicomplete')
      \    }
      \  }
JohnAppleSeed- commented 7 years ago

This solution does work, although I do get 1 when I run :echo has('lambda').

This solution is fine for me but I could see how some people might see it as cumbersome. As long as it works I don't care how it's done.

lifepillar commented 7 years ago

Ah, there was a typo, sorry. Please copy and paste again the first version, it should work now.

JohnAppleSeed- commented 7 years ago

yep works now.

ghost commented 6 years ago

@lifepillar I was able to get '.' to trigger completion via the let g:mucomplete#can_complete setting you gave above. Is there any way to modify that to trigger on '.' but require 2 characters at minimum otherwise like previously?

lifepillar commented 6 years ago

@electric-ladyland Do you mean, like this:

let g:mucomplete#can_complete = {
  \ 'default': {
  \    'omni': { t -> strlen(&l:omnifunc) > 0 && t =~# '\%(\k\k\|\.\)$' }
  \    }
  \  }

This would trigger omni-completion after a dot or after two keyword characters (\k\k).

ghost commented 6 years ago

@lifepillar Exactly, thanks much.