Skip to content

Commit

Permalink
Keep init_results and last 10 calls and messages
Browse files Browse the repository at this point in the history
Towards #19

- Add 'init_result', 'calls', and 'messages' keys to the server info
- Add `lsc#util#shift` function to keep rotating lists of a max size
- Whenever a call is made or a message is received shift in the message
  to calls or messages.
  • Loading branch information
natebosch committed Aug 22, 2017
1 parent b794e57 commit ccd100e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion autoload/lsc/protocol.vim
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ function! s:consumeMessage(server) abort
catch
call lsc#util#error('Could not decode message: '.payload)
endtry
if exists('l:content') | call lsc#dispatch#message(content) | endif
if exists('l:content')
call lsc#util#shift(a:server.messages, 10, content)
call lsc#dispatch#message(content)
endif
let remaining_message = message[message_end:]
let a:server.buffer = remaining_message
return remaining_message != ''
Expand Down
14 changes: 11 additions & 3 deletions autoload/lsc/server.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ if !exists('s:initialized')
" [starting, running, exiting, restarting, exited, unexpected exit, failed]
" - buffer. String received from the server but not processed yet.
" - channel. The communication channel
" - calls. The last 10 calls made to the server
" - messages. The last 10 messages from the server
" - init_result. The response to the initialization call
let s:servers = {}
let s:initialized = v:true
endif
Expand Down Expand Up @@ -71,6 +74,8 @@ function! lsc#server#call(file_type, method, params, ...) abort
let channel = server_info.channel
if ch_status(channel) != 'open' | return v:false | endif
call ch_sendraw(channel, message)
call lsc#util#shift(server_info.calls, 10,
\ {'method': a:method, 'params': a:params, 'id': call_id})
return v:true
endfunction

Expand All @@ -94,12 +99,15 @@ function! s:Start(command) abort
\ 'status': 'starting',
\ 'buffer': '',
\ 'channel': channel,
\ 'calls': [],
\ 'messages': [],
\}
let ch_id = ch_info(channel)['id']
let s:server_names[ch_id] = a:command
function! OnInitialize(init_results) closure abort
if type(a:init_results) == v:t_dict
call s:CheckCapabilities(a:init_results, a:command)
function! OnInitialize(init_result) closure abort
let s:servers[a:command].init_result = a:init_result
if type(a:init_result) == v:t_dict
call s:CheckCapabilities(a:init_result, a:command)
endif
let s:servers[a:command]['status'] = 'running'
for filetype in keys(g:lsc_server_commands)
Expand Down
7 changes: 7 additions & 0 deletions autoload/lsc/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,10 @@ function! s:createOrJumpToPreview(line_count) abort
setlocal buftype=nofile
setlocal noswapfile
endfunction

" Adds [value] to the [list] and removes the earliest entry if it would make the
" list longer than [max_length]
function! lsc#util#shift(list, max_length, value) abort
call add(a:list, a:value)
if len(a:list) > a:max_length | call remove(a:list, 0) | endif
endfunction

0 comments on commit ccd100e

Please sign in to comment.