Skip to content

Commit

Permalink
update tabnine suggestion performance
Browse files Browse the repository at this point in the history
  • Loading branch information
jayli committed Jan 10, 2024
1 parent 3c5c940 commit 3e61d89
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
21 changes: 19 additions & 2 deletions autoload/easycomplete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ let s:first_render_timer = 0
let g:easycomplete_first_render_delay = 500
" lint 中 FloatWidth
let g:easycomplete_lint_float_width = 180
" 控制是否触发tabnine suggest的timer
let g:easycomplete_tabnine_suggest_timer = 0

function! easycomplete#Enable()
call timer_start(800, { -> easycomplete#_enable() })
Expand Down Expand Up @@ -350,6 +352,10 @@ function! easycomplete#CompleteDone()
endif
" bugfix for #88
if g:env_is_nvim
" 触发 tabnine suggest
if !easycomplete#pum#visible() && !easycomplete#IsBacking() && easycomplete#tabnine#ready()
call s:LazyTabNineFire(500)
endif
"TODO v:complete_item 是否是必须的,还需再测试一下
if easycomplete#pum#visible() || (g:easycomplete_first_complete_hit != 1)
call s:zizz()
Expand All @@ -364,6 +370,14 @@ function! easycomplete#CompleteDone()
call s:flush()
endfunction

function! s:LazyTabNineFire(delay)
if g:easycomplete_tabnine_suggest_timer > 0
call timer_stop(g:easycomplete_tabnine_suggest_timer)
let g:easycomplete_tabnine_suggest_timer = 0
endif
let g:easycomplete_tabnine_suggest_timer = timer_start(a:delay, { -> easycomplete#tabnine#fire() })
endfunction

function! easycomplete#WinScrolled()
call easycomplete#pum#WinScrolled()
endfunction
Expand Down Expand Up @@ -2313,8 +2327,8 @@ endfunction
function! easycomplete#CursorHoldI()
if easycomplete#IsBacking()
" do nothting
else
call easycomplete#tabnine#fire()
elseif easycomplete#tabnine#ready()
call s:LazyTabNineFire(30)
endif
endfunction

Expand All @@ -2325,6 +2339,9 @@ function! easycomplete#TextChangedI()
if exists('b:easycomplete_enable') && empty(b:easycomplete_enable)
return
endif
if g:env_is_nvim
call easycomplete#tabnine#LoadingStop()
endif
" TextCHangedP 和 TextChangedI 是互斥的
if g:env_is_nvim && easycomplete#pum#visible()
" TextChangedP
Expand Down
1 change: 1 addition & 0 deletions autoload/easycomplete/sources/tn.vim
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ function! s:TabnineJobCallback(job_id, data, event)
if g:env_is_vim && !pumvisible() && easycomplete#tabnine#SuggestFlagCheck()
call s:SuggestHandler(res_array)
elseif g:env_is_nvim && !easycomplete#pum#visible() && easycomplete#tabnine#SuggestFlagCheck()
call s:SuggestHandler(res_array)
else " 配合pum显示tabnine提示词s
let result_items = s:NormalizeCompleteResult(a:data)
call s:CompleteHandler(result_items)
Expand Down
6 changes: 5 additions & 1 deletion autoload/easycomplete/tabnine.vim
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ function! easycomplete#tabnine#SuggestFlagClear()
endfunction

function! easycomplete#tabnine#TypingType()
return b:tabnine_typing_type
if exists("b:tabnine_typing_type")
return b:tabnine_typing_type
else
return ""
endif
endfunction

function! easycomplete#tabnine#LoadingStart()
Expand Down
6 changes: 6 additions & 0 deletions lua/easycomplete/loading.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
local M = {}
local Util = require "easycomplete.util"
local console = Util.console
local loading_ns = vim.api.nvim_create_namespace('loading_ns')
local loading_timer = vim.loop.new_timer()
local loading_chars = {'','','','','','',''}
Expand All @@ -19,6 +21,10 @@ function M.start()
set_loading_interval(90, function()
count = count + 1
vim.schedule(function()
if cursor == 1 and vim.fn["easycomplete#pum#visible"]() then
M.stop()
return
end
vim.api.nvim_buf_set_extmark(0, loading_ns, vim.fn.line('.') - 1, vim.fn.col('.') - 1, {
id = 2,
virt_text_pos = "eol",
Expand Down
1 change: 1 addition & 0 deletions lua/easycomplete/tabnine.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local Util = require "easycomplete.util"
local loading = require "easycomplete.loading"
local log = Util.log
local console = Util.console
local Export = {}
local tabnine_ns = vim.api.nvim_create_namespace('tabnine_ns')

Expand Down

0 comments on commit 3e61d89

Please sign in to comment.