Skip to content

Commit 2b583fe

Browse files
zbinlinprabirshrestha
authored andcommitted
Use g:ignorecase to indicates whether or not ignorecase to matchs completion word (#392)
* Adds `g:lsp_omni_completion_ignorecase` option to indicates whether or not ignorecase to matchs completion word In most cases, ignorecase is not necessary, so we may add an option to control whether to turn it on. Defaults, `g:lsp_omni_completion_ignorecase` is `0`, meaning case sensitive, if `g:lsp_omni_completion_ignorecase` is set to `1`, or set `ignorecase` options(eg. `:set ignorecase`), it will turn case insensitive on. * Fix CI failed * Remove `g:lsp_omni_completion_ignorecase` options, only use `g:ignorecase` to indicates whether or not ignorecase to matchs completion word * Refactor: cache prefix word
1 parent 2176417 commit 2b583fe

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

autoload/lsp/omni.vim

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,28 @@ function! lsp#omni#complete(findstart, base) abort
6363
while s:completion['status'] is# s:completion_status_pending && !complete_check()
6464
sleep 10m
6565
endwhile
66-
let l:base = tolower(a:base)
67-
let s:completion['matches'] = filter(s:completion['matches'], {_, match -> stridx(tolower(match['word']), l:base) == 0})
66+
let Is_prefix_match = s:create_prefix_matcher(a:base)
67+
let s:completion['matches'] = filter(s:completion['matches'], {_, match -> Is_prefix_match(match['word'])})
6868
let s:completion['status'] = ''
6969
return s:completion['matches']
7070
endif
7171
endif
7272
endfunction
7373

74+
function! s:normalize_word(word) abort
75+
if &g:ignorecase
76+
return tolower(a:word)
77+
else
78+
return a:word
79+
endif
80+
endfunction
81+
82+
function! s:create_prefix_matcher(prefix) abort
83+
let l:prefix = s:normalize_word(a:prefix)
84+
85+
return { word -> stridx(s:normalize_word(word), l:prefix) == 0 }
86+
endfunction
87+
7488
function! s:handle_omnicompletion(server_name, complete_counter, data) abort
7589
if s:completion['counter'] != a:complete_counter
7690
" ignore old completion results

0 commit comments

Comments
 (0)