Close #1428 Implement LSP hover-like functionality for tsserver too
This commit is contained in:
parent
e6fe2d86b8
commit
d8d09c2048
@ -18,6 +18,15 @@ function! ale#hover#ClearLSPData() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#hover#HandleTSServerResponse(conn_id, response) abort
|
function! ale#hover#HandleTSServerResponse(conn_id, response) abort
|
||||||
|
if get(a:response, 'command', '') is# 'quickinfo'
|
||||||
|
\&& has_key(s:hover_map, a:response.request_seq)
|
||||||
|
let l:options = remove(s:hover_map, a:response.request_seq)
|
||||||
|
|
||||||
|
if get(a:response, 'success', v:false) is v:true
|
||||||
|
\&& get(a:response, 'body', v:null) isnot v:null
|
||||||
|
call ale#util#ShowMessage(a:response.body.displayString)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#hover#HandleLSPResponse(conn_id, response) abort
|
function! ale#hover#HandleLSPResponse(conn_id, response) abort
|
||||||
@ -86,8 +95,11 @@ function! s:ShowDetails(linter) abort
|
|||||||
let l:root = l:lsp_details.project_root
|
let l:root = l:lsp_details.project_root
|
||||||
|
|
||||||
if a:linter.lsp is# 'tsserver'
|
if a:linter.lsp is# 'tsserver'
|
||||||
" TODO: Implement this.
|
let l:message = ale#lsp#tsserver_message#Quickinfo(
|
||||||
return
|
\ l:buffer,
|
||||||
|
\ l:line,
|
||||||
|
\ l:column
|
||||||
|
\)
|
||||||
else
|
else
|
||||||
" Send a message saying the buffer has changed first, or the
|
" Send a message saying the buffer has changed first, or the
|
||||||
" hover position probably won't make sense.
|
" hover position probably won't make sense.
|
||||||
@ -109,7 +121,7 @@ endfunction
|
|||||||
|
|
||||||
function! ale#hover#Show() abort
|
function! ale#hover#Show() abort
|
||||||
for l:linter in ale#linter#Get(&filetype)
|
for l:linter in ale#linter#Get(&filetype)
|
||||||
if !empty(l:linter.lsp) && l:linter.lsp isnot# 'tsserver'
|
if !empty(l:linter.lsp)
|
||||||
call s:ShowDetails(l:linter)
|
call s:ShowDetails(l:linter)
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
@ -69,3 +69,11 @@ function! ale#lsp#tsserver_message#References(buffer, line, column) abort
|
|||||||
\ 'file': expand('#' . a:buffer . ':p'),
|
\ 'file': expand('#' . a:buffer . ':p'),
|
||||||
\}]
|
\}]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! ale#lsp#tsserver_message#Quickinfo(buffer, line, column) abort
|
||||||
|
return [0, 'ts@quickinfo', {
|
||||||
|
\ 'line': a:line,
|
||||||
|
\ 'offset': a:column,
|
||||||
|
\ 'file': expand('#' . a:buffer . ':p'),
|
||||||
|
\}]
|
||||||
|
endfunction
|
||||||
|
@ -275,3 +275,16 @@ Execute(ale#lsp#tsserver_message#References() should return correct messages):
|
|||||||
\ }
|
\ }
|
||||||
\ ],
|
\ ],
|
||||||
\ ale#lsp#tsserver_message#References(bufnr(''), 347, 12)
|
\ ale#lsp#tsserver_message#References(bufnr(''), 347, 12)
|
||||||
|
|
||||||
|
Execute(ale#lsp#tsserver_message#Quickinfo() should return correct messages):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ 0,
|
||||||
|
\ 'ts@quickinfo',
|
||||||
|
\ {
|
||||||
|
\ 'file': ale#path#Simplify(g:dir . '/foo/bar.ts'),
|
||||||
|
\ 'line': 347,
|
||||||
|
\ 'offset': 12,
|
||||||
|
\ }
|
||||||
|
\ ],
|
||||||
|
\ ale#lsp#tsserver_message#Quickinfo(bufnr(''), 347, 12)
|
||||||
|
@ -70,6 +70,50 @@ Given python(Some Python file):
|
|||||||
somelongerline
|
somelongerline
|
||||||
bazxyzxyzxyz
|
bazxyzxyzxyz
|
||||||
|
|
||||||
|
Execute(Other messages for the tsserver handler should be ignored):
|
||||||
|
call ale#hover#HandleTSServerResponse(1, {'command': 'foo'})
|
||||||
|
|
||||||
|
Execute(Failed hover responses should be handled correctly):
|
||||||
|
call ale#hover#SetMap({3: {}})
|
||||||
|
call ale#hover#HandleTSServerResponse(
|
||||||
|
\ 1,
|
||||||
|
\ {'command': 'quickinfo', 'request_seq': 3}
|
||||||
|
\)
|
||||||
|
AssertEqual {}, ale#hover#GetMap()
|
||||||
|
|
||||||
|
Given typescript(Some typescript file):
|
||||||
|
foo
|
||||||
|
somelongerline
|
||||||
|
bazxyzxyzxyz
|
||||||
|
|
||||||
|
Execute(tsserver quickinfo responses will null missing bodies should be handled):
|
||||||
|
call ale#hover#SetMap({3: {}})
|
||||||
|
call ale#hover#HandleTSServerResponse(
|
||||||
|
\ 1,
|
||||||
|
\ {
|
||||||
|
\ 'command': 'quickinfo',
|
||||||
|
\ 'request_seq': 3,
|
||||||
|
\ 'success': v:true,
|
||||||
|
\ }
|
||||||
|
\)
|
||||||
|
|
||||||
|
AssertEqual {}, ale#hover#GetMap()
|
||||||
|
|
||||||
|
Execute(tsserver quickinfo displayString values should be displayed):
|
||||||
|
call ale#hover#SetMap({3: {}})
|
||||||
|
call ale#hover#HandleTSServerResponse(
|
||||||
|
\ 1,
|
||||||
|
\ {
|
||||||
|
\ 'command': 'quickinfo',
|
||||||
|
\ 'request_seq': 3,
|
||||||
|
\ 'success': v:true,
|
||||||
|
\ 'body': {'displayString': 'foo bar'},
|
||||||
|
\ }
|
||||||
|
\)
|
||||||
|
|
||||||
|
AssertEqual ['foo bar'], g:echo_list
|
||||||
|
AssertEqual {}, ale#hover#GetMap()
|
||||||
|
|
||||||
Execute(LSP hover responses with just a string should be handled):
|
Execute(LSP hover responses with just a string should be handled):
|
||||||
call HandleValidLSPResult({'contents': 'foobar'})
|
call HandleValidLSPResult({'contents': 'foobar'})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user