Skip to content

Commit

Permalink
Apply for the review
Browse files Browse the repository at this point in the history
- Rename expand_text_simply -> simple_expand_text
- to_col -> _lsp_to_vim
- Rename user_data key
  • Loading branch information
hrsh7th committed Jan 2, 2020
1 parent d955a8a commit 4d9a358
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
11 changes: 6 additions & 5 deletions autoload/lsp/omni.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions autoload/lsp/ui/vim/completion.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -81,17 +81,18 @@ 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]({
\ 'snippet': l:expand_text
\ })
else
" expand text simply.
call s:expand_text_simply(l:expand_text)
call s:simple_expand_text(l:expand_text)
endif
endif

Expand Down Expand Up @@ -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

"
Expand All @@ -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('.'))
Expand All @@ -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

"
Expand Down
8 changes: 4 additions & 4 deletions test/lsp/omni.vimspec
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4d9a358

Please sign in to comment.