Fix #2402 - Handle null LSP references responses

This commit is contained in:
w0rp 2019-03-29 13:42:24 +00:00
parent 32c8bd1fa4
commit a92627e1e1
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
2 changed files with 18 additions and 15 deletions

View File

@ -49,13 +49,15 @@ function! ale#references#HandleLSPResponse(conn_id, response) abort
let l:result = get(a:response, 'result', []) let l:result = get(a:response, 'result', [])
let l:item_list = [] let l:item_list = []
for l:response_item in l:result if type(l:result) is v:t_list
call add(l:item_list, { for l:response_item in l:result
\ 'filename': ale#path#FromURI(l:response_item.uri), call add(l:item_list, {
\ 'line': l:response_item.range.start.line + 1, \ 'filename': ale#path#FromURI(l:response_item.uri),
\ 'column': l:response_item.range.start.character + 1, \ 'line': l:response_item.range.start.line + 1,
\}) \ 'column': l:response_item.range.start.character + 1,
endfor \})
endfor
endif
if empty(l:item_list) if empty(l:item_list)
call ale#util#Execute('echom ''No references found.''') call ale#util#Execute('echom ''No references found.''')

View File

@ -253,14 +253,15 @@ Execute(LSP reference responses should be handled):
Execute(Preview windows should not be opened for empty LSP reference responses): Execute(Preview windows should not be opened for empty LSP reference responses):
call ale#references#SetMap({3: {}}) call ale#references#SetMap({3: {}})
call ale#references#HandleLSPResponse( call ale#references#HandleLSPResponse(1, {'id': 3, 'result': []})
\ 1,
\ { Assert !g:preview_called
\ 'id': 3, AssertEqual {}, ale#references#GetMap()
\ 'result': [ AssertEqual ['echom ''No references found.'''], g:expr_list
\ ],
\ } Execute(LSP reference responses with a null result should be handled):
\) call ale#references#SetMap({3: {}})
call ale#references#HandleLSPResponse(1, {'id': 3, 'result': v:null})
Assert !g:preview_called Assert !g:preview_called
AssertEqual {}, ale#references#GetMap() AssertEqual {}, ale#references#GetMap()