roxma / nvim-completion-manager

:warning: PLEASE USE https://github.com/ncm2/ncm2 INSTEAD
MIT License
917 stars 49 forks source link

registering a source #92

Closed ahmedelgabri closed 7 years ago

ahmedelgabri commented 7 years ago

I'm trying to register github-complete.vim

au User CmSetup call cm#register_source({'name' : 'cm-github',
      \ 'priority': 9,
      \ 'scopes': ['gitcommit'],
      \ 'abbreviation': 'Github',
      \ 'cm_refresh_patterns':['@\w*$',':\w*$', '\#\d*$', '\[[\w\.\-]*]\($', 'github\.com/\w*(/\w*)?$'],
      \ 'cm_refresh': {'omnifunc': 'github_complete#complete'},
      \ })

But it's not really working properly here are some issues:

So what am I doing wrong here?

roxma commented 7 years ago

it doesn't work trigger username completions @_ & github.com/username it doesn't work trigger repo completions github.com/username/repo

You should use 'github\.com\/\w*(\/\w*)?$' instead of 'github\.com/\w*(/\w*)?$'.

But the <c-x><c-o> gets empty result with github.com/, and github.com/repo/. And this is where NCM cache the completion results.

Maybe I should add some option to enable always refreshing of a completion source. But it would make it really slow.

The best solution is to implement it in python, like most other ncm sources. Call self.complete with refresh=True

it always triggers emoji completion not just after :

You could use a higher value 'cm_refresh_min_word_len': 100, to avoid triggering after some random word.

But When I test it with <c-x><c-o>, it could also get triggered after @, considering you have a pattern '@\w*$', ncm cannot workaround this behavior.

The best solution, emoji completion should be a standalone completion source.

ahmedelgabri commented 7 years ago

You are right my regexs were not right, I checked the source code, copied the regex from there & this config works pretty ok now.

au User CmSetup call cm#register_source({'name' : 'cm-github',
      \ 'priority': 9,
      \ 'scopes': ['gitcommit'],
      \ 'abbreviation': 'Github',
      \ 'cm_refresh_patterns':[':\w*$', '#\d*$', '\[[\w\.\-]*]\($', '\%(@\|\<github\.com/\zs\)[[a-zA-Z0-9]-_]\+$', '[[a-zA-Z0-9]-_]\+/[[a-zA-Z0-9]-_]\+$'],
      \ 'cm_refresh': {'omnifunc': 'github_complete#complete'},
      \ })

The best solution is to implement it in python, like most other ncm sources. Call self.complete with refresh=True

You mean reimplement the whole plugin or call the plugin from within Python?

roxma commented 7 years ago

You mean reimplement the whole plugin or call the plugin from within Python?

Call the plugin from python, that would have better control on the refresh triggering.

Reimplement the plugin, that would implement the non-blocking completion, since vimscript is single threaded. github completion requires network access, which is heavy weight.

ahmedelgabri commented 7 years ago

Call the plugin from python, that would have better control on the refresh triggering.

Ok, any pointers on how this can be done?

roxma commented 7 years ago

https://github.com/roxma/nvim-cm-racer is good example.

To call vimscript. You could use the self.nvim object: self.nvim.call('foo', 'arg1', 'arg2')

ahmedelgabri commented 7 years ago

Thanks @roxma, will have a look :)

roxma commented 7 years ago

@ahmedelgabri FYI, this is my attempt to re-implement github-complete.vim: https://github.com/roxma/ncm-github

ahmedelgabri commented 7 years ago

@roxma Great! thanks!

I think it's missing the usage of the token to be able to use it with private repos though https://github.com/rhysd/github-complete.vim#i-want-to-use-github-completevim-on-private-repositories

roxma commented 7 years ago

I don't have private github repo to test this feature.

Send PR if you need it.

ahmedelgabri commented 7 years ago

@roxma I'm trying to work on the tokens/private repo part but I want to know how can I debug this in vim?