mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-07 05:04:28 +08:00
Fix #3273 - Handle missing keys in hover information
This commit is contained in:
@@ -91,11 +91,12 @@ function! ale#hover#HandleLSPResponse(conn_id, response) abort
|
|||||||
|
|
||||||
if type(l:result) is v:t_dict
|
if type(l:result) is v:t_dict
|
||||||
" If the result is an object, then it's markup content.
|
" If the result is an object, then it's markup content.
|
||||||
let l:result = [l:result.value]
|
let l:result = has_key(l:result, 'value') ? [l:result.value] : []
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if type(l:result) is v:t_list
|
if type(l:result) is v:t_list
|
||||||
" Replace objects with text values.
|
" Replace objects with text values.
|
||||||
|
call filter(l:result, '!(type(v:val) is v:t_dict && !has_key(v:val, ''value''))')
|
||||||
call map(l:result, 'type(v:val) is v:t_string ? v:val : v:val.value')
|
call map(l:result, 'type(v:val) is v:t_string ? v:val : v:val.value')
|
||||||
let l:str = join(l:result, "\n")
|
let l:str = join(l:result, "\n")
|
||||||
let l:str = substitute(l:str, '^\s*\(.\{-}\)\s*$', '\1', '')
|
let l:str = substitute(l:str, '^\s*\(.\{-}\)\s*$', '\1', '')
|
||||||
|
|||||||
@@ -133,6 +133,12 @@ Execute(LSP hover responses with markup content should be handled):
|
|||||||
AssertEqual ['markup'], g:echo_list
|
AssertEqual ['markup'], g:echo_list
|
||||||
AssertEqual {}, ale#hover#GetMap()
|
AssertEqual {}, ale#hover#GetMap()
|
||||||
|
|
||||||
|
Execute(LSP hover responses with markup content missing values should be handled):
|
||||||
|
call HandleValidLSPResult({'contents': {'kind': 'something'}})
|
||||||
|
|
||||||
|
AssertEqual [], g:echo_list
|
||||||
|
AssertEqual {}, ale#hover#GetMap()
|
||||||
|
|
||||||
Execute(LSP hover response with lists of strings should be handled):
|
Execute(LSP hover response with lists of strings should be handled):
|
||||||
call HandleValidLSPResult({'contents': [
|
call HandleValidLSPResult({'contents': [
|
||||||
\ "foo\n",
|
\ "foo\n",
|
||||||
@@ -145,6 +151,7 @@ Execute(LSP hover response with lists of strings should be handled):
|
|||||||
Execute(LSP hover response with lists of strings and marked strings should be handled):
|
Execute(LSP hover response with lists of strings and marked strings should be handled):
|
||||||
call HandleValidLSPResult({'contents': [
|
call HandleValidLSPResult({'contents': [
|
||||||
\ {'language': 'rust', 'value': 'foo'},
|
\ {'language': 'rust', 'value': 'foo'},
|
||||||
|
\ {'language': 'foobar'},
|
||||||
\ "bar\n",
|
\ "bar\n",
|
||||||
\]})
|
\]})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user