diff options
-rw-r--r-- | autoload/ale/hover.vim | 18 | ||||
-rw-r--r-- | autoload/ale/lsp/tsserver_message.vim | 8 | ||||
-rw-r--r-- | test/lsp/test_lsp_client_messages.vader | 13 | ||||
-rw-r--r-- | test/test_hover.vader | 44 |
4 files changed, 80 insertions, 3 deletions
diff --git a/autoload/ale/hover.vim b/autoload/ale/hover.vim index 2ccc4ff0..12af877d 100644 --- a/autoload/ale/hover.vim +++ b/autoload/ale/hover.vim @@ -18,6 +18,15 @@ function! ale#hover#ClearLSPData() abort endfunction 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 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 if a:linter.lsp is# 'tsserver' - " TODO: Implement this. - return + let l:message = ale#lsp#tsserver_message#Quickinfo( + \ l:buffer, + \ l:line, + \ l:column + \) else " Send a message saying the buffer has changed first, or the " hover position probably won't make sense. @@ -109,7 +121,7 @@ endfunction function! ale#hover#Show() abort 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) endif endfor diff --git a/autoload/ale/lsp/tsserver_message.vim b/autoload/ale/lsp/tsserver_message.vim index 415fde95..d6919516 100644 --- a/autoload/ale/lsp/tsserver_message.vim +++ b/autoload/ale/lsp/tsserver_message.vim @@ -69,3 +69,11 @@ function! ale#lsp#tsserver_message#References(buffer, line, column) abort \ 'file': expand('#' . a:buffer . ':p'), \}] 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 diff --git a/test/lsp/test_lsp_client_messages.vader b/test/lsp/test_lsp_client_messages.vader index d186f5e4..89a29c8f 100644 --- a/test/lsp/test_lsp_client_messages.vader +++ b/test/lsp/test_lsp_client_messages.vader @@ -275,3 +275,16 @@ Execute(ale#lsp#tsserver_message#References() should return correct messages): \ } \ ], \ 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) diff --git a/test/test_hover.vader b/test/test_hover.vader index 3018249d..18dcebaf 100644 --- a/test/test_hover.vader +++ b/test/test_hover.vader @@ -70,6 +70,50 @@ Given python(Some Python file): somelongerline 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): call HandleValidLSPResult({'contents': 'foobar'}) |