Skip to content

Commit

Permalink
Add case sensitive completion option
Browse files Browse the repository at this point in the history
  • Loading branch information
Quramy committed May 13, 2015
1 parent 43ba793 commit a79c666
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
38 changes: 34 additions & 4 deletions autoload/tsuquyomi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ function! s:is_valid_identifier(symbol_str)
return a:symbol_str =~ '[A-Za-z_\$][A-Za-z_\$0-9]*'
endfunction

let s:complete_call_count = 0
let s:start_time = reltime()
let s:time_arr = []
function! s:debug_time(name)
if 0
call add(s:time_arr, {'name': a:name, 'count': s:complete_call_count, 'elapse': reltime(s:start_time)})
endif
endfunction
function! tsuquyomi#getTime()
let num_row = len(s:time_arr)
let j = len(s:time_arr) - num_row + 1
while j < num_row
let t = s:time_arr[j]
let prev = s:time_arr[j - 1]
echo reltimestr(t.elapse) t.count t.name reltimestr(reltime(prev.elapse, t.elapse))
let j = j + 1
endwhile
endfunction

" ### Utilites }}}

" ### Public functions {{{
Expand Down Expand Up @@ -184,7 +203,9 @@ function! tsuquyomi#setPreviewOption()
endfunction

function! tsuquyomi#makeCompleteMenu(file, line, offset, entryNames)
"call s:debug_time('tsCompletionEntryDetail')
let res_list = tsuquyomi#tsClient#tsCompletionEntryDetails(a:file, a:line, a:offset, a:entryNames)
"call s:debug_time('tsCompletionEntryDetail_done')
let display_texts = []
for result in res_list
call add(display_texts, s:joinPartsIgnoreBreak(result.displayParts, '{...}'))
Expand Down Expand Up @@ -232,6 +253,9 @@ endfunction

function! tsuquyomi#complete(findstart, base)

let s:complete_call_count = s:complete_call_count + 1
let s:start_time = reltime()

if len(s:checkOpenAndMessage([expand('%:p')])[1])
return
endif
Expand All @@ -247,17 +271,20 @@ function! tsuquyomi#complete(findstart, base)
endwhile

if(a:findstart)
"call s:debug_time('before_flash')
call s:flash()
"call s:debug_time('after_flash')
return l:start - 1
else
let l:file = expand('%:p')
let l:res_dict = {'words': []}
"call s:debug_time('before_tsCompletions')
let l:res_list = tsuquyomi#tsClient#tsCompletions(l:file, l:line, l:start, a:base)
"call s:debug_time('after_tsCompletions')
let enable_menu = stridx(&completeopt, 'menu') != -1

let length = strlen(a:base)

if enable_menu
call s:debug_time('start_menu')
let [has_info, siginfo] = tsuquyomi#makeCompleteInfo(l:file, l:line, l:start)
let size = g:tsuquyomi_completion_chank_size
let j = 0
Expand All @@ -267,14 +294,17 @@ function! tsuquyomi#complete(findstart, base)
let upper = min([(j + 1) * size, len(l:res_list)])
for i in range(j * size, upper - 1)
let info = l:res_list[i]
if !length || info.name[0:length - 1] == a:base
if !length
\ || !g:tsuquyomi_completion_case_sensitive && info.name[0:length - 1] == a:base
\ || g:tsuquyomi_completion_case_sensitive && info.name[0:length - 1] ==# a:base
let l:item = {'word': info.name}
call add(entries, info.name)
call add(items, l:item)
endif
endfor

"call s:debug_time('before_completeMenu'.j)
let menus = tsuquyomi#makeCompleteMenu(l:file, l:line, l:start, entries)
"call s:debug_time('after_completeMenu'.j)
let idx = 0
for menu in menus
let items[idx].menu = menu
Expand Down
5 changes: 5 additions & 0 deletions doc/tsuquyomi.jax
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ g:tsuquyomi_definition_split (デフォルト値 0)
* 1: |:split|
* 2: |:vsplit|

*g:tsuquyomi_completion_case_sensitive*
g:tsuquyomi_completion_case_sensitive (デフォルト値 0)
|tsuquyomi#complete|実行時に補完候補をcase-sensitiveに
探索するかどうか.

------------------------------------------------------------------------------
キーマッピング *tsuquyomi-key-mappings*

Expand Down
5 changes: 5 additions & 0 deletions doc/tsuquyomi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ g:tsuquyomi_definition_split (default 0)
* 1: |:split|
* 2: |:vplit|

*g:tsuquyomi_completion_case_sensitive*
g:tsuquyomi_completion_case_sensitive (default 0)
Whether to search completion case-sensitively when
|tsuquyomi#complete|.

------------------------------------------------------------------------------
KEY MAPPINGS *tsuquyomi-key-mappings*

Expand Down
4 changes: 3 additions & 1 deletion plugin/tsuquyomi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ let g:tsuquyomi_nodejs_path =
let g:tsuquyomi_waittime_after_open=
\ get(g:, 'tsuquyomi_waittime_after_open', 0.01)
let g:tsuquyomi_completion_chank_size =
\ get(g:, 'tsuquyomi_completion_chank_size', 15)
\ get(g:, 'tsuquyomi_completion_chank_size', 80)
let g:tsuquyomi_completion_case_sensitive =
\ get(g:, 'tsuquyomi_completion_case_sensitive', 0)
let g:tsuquyomi_definition_split =
\ get(g:, 'tsuquyomi_definition_split', 0)
" Global options defintion. }}}
Expand Down

0 comments on commit a79c666

Please sign in to comment.