diff --git a/autoload/lsp/omni.vim b/autoload/lsp/omni.vim index 70764cc4d..595450c2a 100644 --- a/autoload/lsp/omni.vim +++ b/autoload/lsp/omni.vim @@ -300,7 +300,7 @@ endfunction " " This function should call at `CompleteDone` only if not empty `v:completed_item`. " -function! lsp#omni#clear_managed_user_data_map() abort +function! lsp#omni#_clear_managed_user_data_map() abort let s:managed_user_data_key_base = 0 let s:managed_user_data_map = {} endfunction @@ -309,10 +309,11 @@ endfunction " create item's user_data. " function! s:create_user_data(completion_item, server_name) abort - let l:user_data_key = 'vim-lsp/' . string(s:managed_user_data_key_base) - let s:managed_user_data_map[l:user_data_key] = {} - let s:managed_user_data_map[l:user_data_key]['server_name'] = a:server_name - let s:managed_user_data_map[l:user_data_key]['completion_item'] = a:completion_item + let l:user_data_key = 'vim-lsp/key/' . string(s:managed_user_data_key_base) + let s:managed_user_data_map[l:user_data_key] = { + \ 'server_name': a:server_name, + \ 'completion_item': a:completion_item + \ } let s:managed_user_data_key_base += 1 return l:user_data_key endfunction diff --git a/autoload/lsp/ui/vim/completion.vim b/autoload/lsp/ui/vim/completion.vim index 258e0c2c4..d6561c56d 100644 --- a/autoload/lsp/ui/vim/completion.vim +++ b/autoload/lsp/ui/vim/completion.vim @@ -32,7 +32,7 @@ function! s:on_complete_done() abort let l:managed_user_data = lsp#omni#get_managed_user_data_from_completed_item(v:completed_item) " Clear managed user_data. - call lsp#omni#clear_managed_user_data_map() + call lsp#omni#_clear_managed_user_data_map() " If managed user_data does not exists, skip it. if empty(l:managed_user_data) @@ -81,9 +81,10 @@ function! s:on_complete_done_after() abort \ l:completed_item, \ l:completion_item \ ) + if exists('g:lsp_snippets_expand_snippet') && len(g:lsp_snippets_expand_snippet) > 0 " vim-lsp-snippets expects commit characters removed. - call s:expand_text_simply(v:completed_item['word']) + call s:simple_expand_text(v:completed_item['word']) elseif exists('g:lsp_snippet_expand') && len(g:lsp_snippet_expand) > 0 " other snippet integartion point. call g:lsp_snippet_expand[0]({ @@ -91,7 +92,7 @@ function! s:on_complete_done_after() abort \ }) else " expand text simply. - call s:expand_text_simply(l:expand_text) + call s:simple_expand_text(l:expand_text) endif endif @@ -196,10 +197,7 @@ function! s:clear_inserted_text(line, position, completed_item, completion_item) \ }]) " Move to complete start position. - call cursor( - \ l:range['start']['line'] + 1, - \ lsp#utils#to_col('%', l:range['start']['line'] + 1, l:range['start']['character']) - \ ) + call cursor(lsp#utils#position#_lsp_to_vim('%', l:range['start'])) endfunction " @@ -218,7 +216,7 @@ endfunction " " Expand text " -function! s:expand_text_simply(text) abort +function! s:simple_expand_text(text) abort let l:pos = { \ 'line': line('.') - 1, \ 'character': lsp#utils#to_char('%', line('.'), col('.')) @@ -239,10 +237,12 @@ function! s:expand_text_simply(text) abort \ }, \ 'newText': l:text \ }]) - call cursor( - \ l:pos['line'] + 1, - \ lsp#utils#to_col('%', l:pos['line'] + 1, l:pos['character']) + l:offset - \ ) + + let l:pos = lsp#utils#position#_lsp_to_vim('%', { + \ 'line': l:pos['line'], + \ 'character': l:pos['character'] + l:offset + \ }) + call cursor(l:pos) endfunction " diff --git a/test/lsp/omni.vimspec b/test/lsp/omni.vimspec index 8e62321c5..fd16a5c62 100644 --- a/test/lsp/omni.vimspec +++ b/test/lsp/omni.vimspec @@ -1,7 +1,7 @@ Describe lsp#omni Before each - call lsp#omni#clear_managed_user_data_map() + call lsp#omni#_clear_managed_user_data_map() End Describe lsp#omni#get_vim_completion_item @@ -22,7 +22,7 @@ Describe lsp#omni \ 'empty': 1, \ 'kind': 'function', \ 'menu': 'my-detail', - \ 'user_data': 'vim-lsp/0' + \ 'user_data': 'vim-lsp/key/0' \} Assert Equals(lsp#omni#get_vim_completion_item(item), want) @@ -56,7 +56,7 @@ Describe lsp#omni \ 'empty': 1, \ 'kind': 'function', \ 'menu': 'my-detail', - \ 'user_data': 'vim-lsp/0' + \ 'user_data': 'vim-lsp/key/0' \} let got = lsp#omni#get_vim_completion_item(item) @@ -84,7 +84,7 @@ Describe lsp#omni \ 'empty': 1, \ 'kind': 'function', \ 'menu': 'my-detail more-detail', - \ 'user_data': 'vim-lsp/0' + \ 'user_data': 'vim-lsp/key/0' \} Assert Equals(lsp#omni#get_vim_completion_item(item), want)