diff options
author | w0rp <devw0rp@gmail.com> | 2017-06-07 17:05:28 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-06-07 17:05:34 +0100 |
commit | f61c6d4c0ed9827aa0b798dc39233817b0813380 (patch) | |
tree | 69b47447b6eaaaf412169182434cc3694a51d5ce /autoload | |
parent | 71257979aa0916a66e8359505c4424888d80fd80 (diff) | |
download | ale-f61c6d4c0ed9827aa0b798dc39233817b0813380.zip |
Add support for generating essential tsserver messages
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/lsp.vim | 32 | ||||
-rw-r--r-- | autoload/ale/lsp/tsserver_message.vim | 34 |
2 files changed, 65 insertions, 1 deletions
diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim index 36620228..76d0c8df 100644 --- a/autoload/ale/lsp.vim +++ b/autoload/ale/lsp.vim @@ -42,9 +42,35 @@ function! ale#lsp#GetNextMessageID() abort return l:id endfunction +" TypeScript messages use a different format. +function! s:CreateTSServerMessageData(message) abort + let l:is_notification = a:message[0] + + let l:obj = { + \ 'seq': v:null, + \ 'type': 'request', + \ 'command': a:message[1][3:], + \} + + if !l:is_notification + let l:obj.seq = ale#lsp#GetNextMessageID() + endif + + if len(a:message) > 2 + let l:obj.arguments = a:message[2] + endif + + let l:data = json_encode(l:obj) + return [l:is_notification ? 0 : l:obj.seq, l:data] +endfunction + " Given a List of one or two items, [method_name] or [method_name, params], " return a List containing [message_id, message_data] function! ale#lsp#CreateMessageData(message) abort + if a:message[1] =~# '^ts@' + return s:CreateTSServerMessageData(a:message) + endif + let l:is_notification = a:message[0] let l:obj = { @@ -117,7 +143,11 @@ function! ale#lsp#HandleMessage(conn, message) abort " Call our callbacks. for l:response in l:response_list - let l:callback = a:conn.callback_map.pop(l:response.id) + let l:id = has_key(l:response, 'seq') + \ ? l:response.seq + \ : l:response.id + + let l:callback = a:conn.callback_map.pop(l:id) call ale#util#GetFunction(l:callback)(l:response) endfor endfunction diff --git a/autoload/ale/lsp/tsserver_message.vim b/autoload/ale/lsp/tsserver_message.vim new file mode 100644 index 00000000..fff1797e --- /dev/null +++ b/autoload/ale/lsp/tsserver_message.vim @@ -0,0 +1,34 @@ +" Author: w0rp <devw0rp@gmail.com> +" Description: tsserver message implementations +" +" Messages in this movie will be returned in the format +" [is_notification, command_name, params?] +" +" Every command must begin with the string 'ts@', which will be used to +" detect the different message format for tsserver, and this string will +" be removed from the actual command name, + +function! ale#lsp#tsserver_message#Open(buffer) abort + return [1, 'ts@open', {'file': expand('#' . a:buffer . ':p')}] +endfunction + +function! ale#lsp#tsserver_message#Close(buffer) abort + return [1, 'ts@close', {'file': expand('#' . a:buffer . ':p')}] +endfunction + +function! ale#lsp#tsserver_message#Change(buffer) abort + let l:lines = getbufline(a:buffer, 1, '$') + + return [1, 'ts@change', { + \ 'file': expand('#' . a:buffer . ':p'), + \ 'line': 1, + \ 'offset': 1, + \ 'endLine': len(l:lines), + \ 'endOffset': len(l:lines[-1]), + \ 'insertString': join(l:lines, "\n"), + \}] +endfunction + +function! ale#lsp#tsserver_message#Geterr(buffer) abort + return [1, 'ts@geterr', {'files': [expand('#' . a:buffer . ':p')]}] +endfunction |