Skip to content

Commit

Permalink
bugfix for #302
Browse files Browse the repository at this point in the history
  • Loading branch information
jayli committed Sep 15, 2024
1 parent 316e938 commit 17e4a08
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion autoload/easycomplete/sources/ts.vim
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,62 @@ function! easycomplete#sources#ts#CompleteCallback(item)
call s:DoComplete(easycomplete#context(), l:easycomplete_menu_list)
endfunction

" #302
function! s:filter(matches)
let ctx = easycomplete#context()
let matches = a:matches
let matches = copy(matches)
if ctx['typed'] =~ '\(\w\+\.\)\{-1,}$'
call filter(matches, function("s:TsHack_S_DotFilter"))
endif
let matches = map(copy(matches), function("s:TsHack_A_DotMap"))
return matches
endfunction

function! s:TsHack_S_DotFilter(key, val)
if has_key(a:val, "abbr") && has_key(a:val, "word")
\ && stridx(get(a:val, "word"), ".") > 0
let ts_typing_word = s:TsHack_GetTsTypingWord()
return stridx(get(a:val, "word"), ts_typing_word) == 0
else
return v:false
endif
endfunction

function! s:TsHack_A_DotMap(key, val)
if has_key(a:val, "abbr") && has_key(a:val, "word")
\ && stridx(get(a:val, "word"), ".") > 0
let ctx = easycomplete#context()
let ts_typing_word_for_map = s:TsHack_GetTsTypingWord()
if ctx["char"] == "."
let a:val.word = substitute(get(a:val, "word"), "^" . ts_typing_word_for_map, "", "g")
let a:val.abbr = a:val.word
else
let word = easycomplete#util#GetTypingWord()
let a:val.word = substitute(get(a:val, "word"), "^" . ts_typing_word_for_map[:-1 * ( 1 + strlen(word))], "", "g")
let a:val.abbr = a:val.word
endif
let ts_typing_word_for_map = s:TsHack_GetTsTypingWord()
endif
return a:val
endfunction

function! s:TsHack_GetTsTypingWord()
let start = col('.') - 1
let line = getline('.')
let width = 0
let regx = '[a-zA-Z0-9_.]'
while start > 0 && line[start - 1] =~ regx
let start = start - 1
let width = width + 1
endwhile
let word = strpart(line, start, width)
return word
endfunction

function! s:DoComplete(ctx, menu_list)
call easycomplete#complete(s:opt['name'], a:ctx, a:ctx['startcol'], a:menu_list)
let l:menu_list = s:filter(a:menu_list)
call easycomplete#complete(s:opt['name'], a:ctx, a:ctx['startcol'], l:menu_list)
endfunction

" 获取 keyword 的 More Info,menulist 是需要获取 Info 的 item 数组
Expand Down

0 comments on commit 17e4a08

Please sign in to comment.