Disconnect when port file disappears
This commit is contained in:
parent
91e3b35403
commit
6e7f22766a
@ -148,8 +148,7 @@ function! s:repl.try(function, ...) dict abort
|
|||||||
try
|
try
|
||||||
return call(self.connection[a:function], a:000, self.connection)
|
return call(self.connection[a:function], a:000, self.connection)
|
||||||
catch /^\w\+ Connection Error:/
|
catch /^\w\+ Connection Error:/
|
||||||
call filter(s:repl_paths, 'v:val isnot self')
|
call s:unregister_connection(self.connection)
|
||||||
call filter(s:repls, 'v:val isnot self')
|
|
||||||
throw v:exception
|
throw v:exception
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
@ -200,6 +199,11 @@ function! s:register_connection(conn, ...) abort
|
|||||||
return s:repls[0]
|
return s:repls[0]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:unregister_connection(conn) abort
|
||||||
|
call filter(s:repl_paths, 'v:val.connection.transport isnot# a:conn.transport')
|
||||||
|
call filter(s:repls, 'v:val.connection.transport isnot# a:conn.transport')
|
||||||
|
endfunction
|
||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
" :Connect {{{1
|
" :Connect {{{1
|
||||||
|
|
||||||
@ -1216,7 +1220,7 @@ function! s:hunt(start, anchor, pattern) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
if !exists('s:leiningen_repl_ports')
|
if !exists('s:leiningen_repl_ports')
|
||||||
let s:leiningen_repl_ports = {}
|
let s:leiningen_repls = {}
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! s:portfile() abort
|
function! s:portfile() abort
|
||||||
@ -1237,16 +1241,25 @@ endfunction
|
|||||||
|
|
||||||
|
|
||||||
function! s:leiningen_connect() abort
|
function! s:leiningen_connect() abort
|
||||||
|
for [k, v] in items(s:leiningen_repls)
|
||||||
|
if getfsize(v.file) <= 0
|
||||||
|
call remove(s:leiningen_repls, k)
|
||||||
|
call s:unregister_connection(v.connection)
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
|
||||||
let portfile = s:portfile()
|
let portfile = s:portfile()
|
||||||
if empty(portfile)
|
if empty(portfile)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if getfsize(portfile) > 0 && getftime(portfile) !=# get(s:leiningen_repl_ports, b:leiningen_root, -1)
|
if getfsize(portfile) > 0 && getftime(portfile) !=# get(get(s:leiningen_repls, b:leiningen_root, {}), 'time', -1)
|
||||||
let port = matchstr(readfile(portfile, 'b', 1)[0], '\d\+')
|
let port = matchstr(readfile(portfile, 'b', 1)[0], '\d\+')
|
||||||
let s:leiningen_repl_ports[b:leiningen_root] = getftime(portfile)
|
let s:leiningen_repls[b:leiningen_root] = {'time': getftime(portfile), 'file': portfile}
|
||||||
try
|
try
|
||||||
call s:register_connection(nrepl#fireplace_connection#open(port), b:leiningen_root)
|
let conn = nrepl#fireplace_connection#open(port)
|
||||||
|
let s:leiningen_repls[b:leiningen_root].connection = conn
|
||||||
|
call s:register_connection(conn, b:leiningen_root)
|
||||||
catch /^nREPL Connection Error:/
|
catch /^nREPL Connection Error:/
|
||||||
if &verbose
|
if &verbose
|
||||||
echohl WarningMSG
|
echohl WarningMSG
|
||||||
|
Loading…
Reference in New Issue
Block a user