Skip to content

Commit

Permalink
Merge pull request #299 from phongnh/enable-tabnine-based-on-variable
Browse files Browse the repository at this point in the history
Enable Tabnine source based on variable
  • Loading branch information
jayli authored Oct 24, 2024
2 parents 3e07efa + dd1ee12 commit 680508d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
10 changes: 7 additions & 3 deletions autoload/easycomplete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ function! easycomplete#typing()

if !easycomplete#FireCondition()
" tabnine
if easycomplete#sources#tn#available() && easycomplete#sources#tn#FireCondition()
if s:TabnineSupports() && easycomplete#sources#tn#FireCondition()
call s:flush()
call timer_start(20, { -> easycomplete#sources#tn#refresh(v:true) })
endif
Expand Down Expand Up @@ -1108,7 +1108,7 @@ function! s:CompleteMatchAction()
call s:StopZizz()
let ctx = easycomplete#context()
" tabnine
if easycomplete#sources#tn#available()
if s:TabnineSupports()
call easycomplete#sources#tn#refresh()
endif
let l:vim_word = s:GetTypingWordByGtx()
Expand Down Expand Up @@ -2016,6 +2016,10 @@ function! s:LetCompleteTaskQueueAllDone()
endfor
endfunction

function! s:TabnineSupports() abort
return g:easycomplete_tabnine_enable && easycomplete#sources#tn#available()
endfunction

function! easycomplete#SnipSupports()
return s:SnipSupports()
endfunction
Expand Down Expand Up @@ -2403,7 +2407,7 @@ function! easycomplete#TextChangedP()
let b:old_changedtick = b:changedtick
elseif g:env_is_vim && pumvisible() && !s:zizzing()
" tabnine, 空格 trigger 出的 tabnine menu 敲入字母后的逻辑
if len(easycomplete#GetStuntMenuItems()) == 0 && easycomplete#sources#tn#available()
if len(easycomplete#GetStuntMenuItems()) == 0 && s:TabnineSupports()
" nvim 中的 paste text 行为异常,空格弹出 pum 后直接 paste 时,c-y 会把
" 菜单关掉的同时也把 pasted text 清空,应该是nvim的bug,这里用c-x,c-z 代替
if has('nvim') && empty(g:easycomplete_insert_char)
Expand Down
16 changes: 9 additions & 7 deletions plugin/easycomplete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,15 @@ augroup easycomplete#PluginRegister
\ 'completor': function('easycomplete#sources#directory#completor'),
\ })

au User easycomplete_default_plugin call easycomplete#RegisterSource({
\ 'name': 'tn',
\ 'whitelist': ['*'],
\ 'completor': function('easycomplete#sources#tn#completor'),
\ 'constructor' :function('easycomplete#sources#tn#constructor'),
\ 'command': 'TabNine',
\ })
if g:easycomplete_tabnine_enable
au User easycomplete_default_plugin call easycomplete#RegisterSource({
\ 'name': 'tn',
\ 'whitelist': ['*'],
\ 'completor': function('easycomplete#sources#tn#completor'),
\ 'constructor': function('easycomplete#sources#tn#constructor'),
\ 'command': 'TabNine',
\ })
endif

au User easycomplete_default_plugin call easycomplete#RegisterSource({
\ 'name': 'buf',
Expand Down

0 comments on commit 680508d

Please sign in to comment.