Skip to content

Commit e7f8936

Browse files
committed
性能优化
1 parent f05a466 commit e7f8936

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

autoload/easycomplete/action/completion.vim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function! s:HandleLspCallback(server_name, plugin_name, data) abort
4141
" call s:console('<--', 'lsp response', reltimestr(reltime(g:xx)))
4242
if easycomplete#IsBacking() | return | endif
4343
let l:ctx = easycomplete#context()
44+
let l:word = l:ctx["typing"]
4445
if easycomplete#lsp#client#is_error(a:data) || !has_key(a:data, 'response') ||
4546
\ !has_key(a:data['response'], 'result')
4647
call easycomplete#complete(a:plugin_name, l:ctx, l:ctx['startcol'], [])
@@ -52,22 +53,22 @@ function! s:HandleLspCallback(server_name, plugin_name, data) abort
5253
return
5354
endif
5455

55-
let l:result = s:GetLspCompletionResult(a:server_name, a:data, a:plugin_name)
56+
let l:result = s:GetLspCompletionResult(a:server_name, a:data, a:plugin_name, l:word)
5657
let l:matches = l:result['matches']
5758
let l:startcol = l:ctx['startcol']
5859

5960
let l:matches = s:MatchResultFilterPipe(a:plugin_name, l:matches, l:ctx)
6061
call easycomplete#complete(a:plugin_name, l:ctx, l:startcol, l:matches)
6162
endfunction
6263

63-
function! s:GetLspCompletionResult(server_name, data, plugin_name) abort
64+
function! s:GetLspCompletionResult(server_name, data, plugin_name, word) abort
6465
let l:result = a:data['response']['result']
6566
let l:response = a:data['response']
6667

6768
" 这里包含了 info document 和 matches
6869
let g:xx = reltime()
6970
" 192 个元素,55 ms
70-
let l:completion_result = easycomplete#util#GetVimCompletionItems(l:response, a:plugin_name)
71+
let l:completion_result = easycomplete#util#GetVimCompletionItems(l:response, a:plugin_name, a:word)
7172
" call s:console('<--', 'TODOTODOTODO', reltimestr(reltime(g:xx)), len(l:completion_result['items']))
7273
return {'matches': l:completion_result['items'], 'incomplete': l:completion_result['incomplete'] }
7374
endfunction

autoload/easycomplete/util.vim

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,9 +1702,9 @@ function! s:BadBoy.Nim(item, typing_word)
17021702
if &filetype != "nim" | return v:false | endif
17031703
let word = get(a:item, "label", "")
17041704
if empty(word) | return v:true | endif
1705-
let pos = stridx(word, a:typing_word)
17061705
if len(a:typing_word) == 1
1707-
if pos >= 0 && pos <= 5
1706+
let pos = stridx(word, a:typing_word)
1707+
if pos >= 0 && pos <= 3
17081708
return v:false
17091709
else
17101710
return v:true
@@ -1826,7 +1826,7 @@ function! s:NormalizeFunctionalSnip(insertText)
18261826
endfunction
18271827

18281828
" GetVimCompletionItems {{{
1829-
function! easycomplete#util#GetVimCompletionItems(response, plugin_name)
1829+
function! easycomplete#util#GetVimCompletionItems(response, plugin_name, word)
18301830
let l:result = a:response['result']
18311831
if type(l:result) == type([])
18321832
let l:items = l:result
@@ -1841,7 +1841,7 @@ function! easycomplete#util#GetVimCompletionItems(response, plugin_name)
18411841

18421842
let l:vim_complete_items = []
18431843
let l:items_length = len(l:items)
1844-
let typing_word = easycomplete#util#GetTypingWord()
1844+
let typing_word = a:word
18451845
for l:completion_item in l:items
18461846
if &filetype == "nim" && s:BadBoy.Nim(l:completion_item, typing_word) | continue | endif
18471847
if &filetype == "vim" && s:BadBoy.Vim(l:completion_item, typing_word) | continue | endif
@@ -1995,13 +1995,16 @@ function! s:NormalizeLspInfo(info)
19951995
endif
19961996
let l:li = split(info, "\n")
19971997
let l:str = []
1998-
1999-
for item in l:li
2000-
if item ==# '```' || item =~ "^```\[a-zA-Z0-9]\\{-}$"
2001-
continue
2002-
endif
2003-
call add(l:str, item)
2004-
endfor
1998+
if &filetype == "vim"
1999+
let l:str = l:li
2000+
else
2001+
for item in l:li
2002+
if item ==# '```' || item =~ "^```\[a-zA-Z0-9]\\{-}$"
2003+
continue
2004+
endif
2005+
call add(l:str, item)
2006+
endfor
2007+
endif
20052008
return l:str
20062009
endfunction
20072010

0 commit comments

Comments
 (0)