From 41143f440a5855e1424650b41894c19d6b6da16a Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 30 Jan 2017 12:39:53 -0800 Subject: [PATCH] Fix some v:null errors --- autoload/langserver/callbacks.vim | 6 +++--- autoload/langserver/hover.vim | 22 +++++++++++++++++++--- autoload/langserver/util.vim | 8 ++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/autoload/langserver/callbacks.vim b/autoload/langserver/callbacks.vim index d8a0f2f..fd6980b 100644 --- a/autoload/langserver/callbacks.vim +++ b/autoload/langserver/callbacks.vim @@ -83,17 +83,17 @@ endfunction function! langserver#callbacks#data(id, data, event) abort call langserver#log#callback(a:id, a:data, a:event) + let g:last_response = a:data if type(a:data) != type({}) - return '' + return {} endif if has_key(a:data, 'response') let l:parsed_data = a:data['response']['result'] else - return '' + return {} endif - let g:last_response = l:parsed_data return l:parsed_data endfunction diff --git a/autoload/langserver/hover.vim b/autoload/langserver/hover.vim index 1d1f8d6..c230bab 100644 --- a/autoload/langserver/hover.vim +++ b/autoload/langserver/hover.vim @@ -1,5 +1,17 @@ function! langserver#hover#callback(id, data, event) abort let l:parsed_data = langserver#callbacks#data(a:id, a:data, a:event) + + if langserver#util#null_check(l:parsed_data) + call langserver#hover#display([], [ + \ { + \ 'language': 'LSP', + \ 'value': 'Unable to retrieve hover information' + \ }, + \ ], + \ ) + return + endif + if l:parsed_data == {} return endif @@ -41,9 +53,13 @@ function! langserver#hover#display(range, data) abort echo l:hover_string - return timer_start(3000, function('s:delete_highlight')) + if !empty(a:range) + return timer_start(3000, function('s:delete_highlight')) + endif endfunction -function! s:delete_highlight() abort - silent! call matchdelete(s:my_last_highlight) +function! s:delete_highlight(timer_id) abort + if exists('s:my_last_highlight') + silent! call matchdelete(s:my_last_highlight) + endif endfunction diff --git a/autoload/langserver/util.vim b/autoload/langserver/util.vim index 82cd0fe..1bd841c 100644 --- a/autoload/langserver/util.vim +++ b/autoload/langserver/util.vim @@ -286,3 +286,11 @@ function! langserver#util#get_line(loc_bufnr, loc_filename, loc_line) abort return l:loc_text endfunction + +function! langserver#util#null_check(item) + if type(a:item) == type(v:null) + return v:true + else + return v:false + endif +endfunction