Skip to content

Commit

Permalink
Add timeout to completionItem/resolve in completion.vim
Browse files Browse the repository at this point in the history
  • Loading branch information
hrsh7th committed Jan 2, 2020
1 parent 8d44d86 commit fd78bdd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions autoload/lsp/client.vim
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,13 @@ function! s:lsp_send(id, opts, type) abort " opts = { id?, method?, result?, par
if (a:type == s:send_type_request)
let l:id = l:request['id']
if get(a:opts, 'sync', 0) !=# 0
let l:start_time = reltime()

let l:timeout = get(a:opts, 'sync_timeout', -1)
while has_key(l:ctx['requests'], l:request['id'])
if reltimefloat(reltime(l:start_time)) > l:timeout && l:timeout != -1
throw 'lsp#client: timeout'
endif
sleep 1m
endwhile
endif
Expand Down
3 changes: 2 additions & 1 deletion autoload/lsp/ui/vim/completion.vim
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ function! s:resolve_completion_item(completion_item, server_name) abort
let l:ctx = {}
let l:ctx['response'] = {}
function! l:ctx['callback'](data) abort
let l:self['response'] = a:data.response
let l:self['response'] = a:data['response']
endfunction

call lsp#send_request(a:server_name, {
\ 'method': 'completionItem/resolve',
\ 'params': a:completion_item,
\ 'sync': 1,
\ 'sync_timeout': g:lsp_completion_resolve_timeout,
\ 'on_notification': function(l:ctx['callback'], [], l:ctx)
\ })

Expand Down
6 changes: 6 additions & 0 deletions doc/vim-lsp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,12 @@ g:lsp_snippet_expand *g:lsp_snippet_expand*
The integration point to other snippet plugin.
vim-lsp may invoke the first item of this value when it needs snippet expansion.

g:lsp_completion_resolve_timeout *g:lsp_completion_resolve_timeout*
Type: |Number|
Default: `200`

The `completionItem/resolve` request's timeout value.
If your vim freeze at `CompleteDone`, you can set this value to 0.

==============================================================================
FUNCTIONS *vim-lsp-functions*
Expand Down
1 change: 1 addition & 0 deletions plugin/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let g:lsp_hover_conceal = get(g:, 'lsp_hover_conceal', 1)
let g:lsp_ignorecase = get(g:, 'lsp_ignorecase', &ignorecase)
let g:lsp_semantic_enabled = get(g:, 'lsp_semantic_enabled', 1)
let g:lsp_text_document_did_save_delay = get(g:, 'lsp_text_document_did_save_delay', -1)
let g:lsp_completion_resolve_timeout = get(g:, 'lsp_completion_resolve_timeout', 200)

let g:lsp_get_vim_completion_item = get(g:, 'lsp_get_vim_completion_item', [function('lsp#omni#default_get_vim_completion_item')])
let g:lsp_get_supported_capabilities = get(g:, 'lsp_get_supported_capabilities', [function('lsp#default_get_supported_capabilities')])
Expand Down

0 comments on commit fd78bdd

Please sign in to comment.