Skip to content

Commit

Permalink
fix: Update elin#server#connect to handle on_close to reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Feb 20, 2024
1 parent a61ea7d commit ca613b5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion autoload/elin/server.vim
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,25 @@ endfunction

function! s:connect(port) abort
try
let s:conn = elin#internal#rpc#connect(printf('localhost:%s', a:port))
let s:conn = elin#internal#rpc#connect(
\ printf('localhost:%s', a:port),
\ {'on_close': funcref('s:on_close')},
\ )
let s:port = a:port
return v:true
catch
return v:false
endtry
endfunction

function! s:on_close(...) abort
echom 'Elin server connection is closed'
if s:port is# v:null
return
endif
call timer_start(100, {_ -> elin#server#connect(s:port)})
endfunction

function! elin#server#disconnect() abort
if s:conn is# v:null
return
Expand Down

0 comments on commit ca613b5

Please sign in to comment.