Clean up our sessions

This commit is contained in:
Tim Pope 2014-01-08 20:40:42 -05:00
parent 18d60a3fa5
commit 02f28c5dbb

View File

@ -58,6 +58,17 @@ function! nrepl#fireplace_connection#prompt() abort
return fireplace#input_host_port() return fireplace#input_host_port()
endfunction endfunction
if !exists('g:nrepl_fireplace_sessions')
let g:nrepl_fireplace_sessions = {}
endif
augroup nrepl_fireplace_connection
autocmd!
autocmd VimLeave * for s:session in values(g:nrepl_fireplace_sessions)
\ | call s:session.close()
\ | endfor
augroup END
function! nrepl#fireplace_connection#open(arg) abort function! nrepl#fireplace_connection#open(arg) abort
if a:arg =~# '^\d\+$' if a:arg =~# '^\d\+$'
let host = 'localhost' let host = 'localhost'
@ -75,12 +86,27 @@ function! nrepl#fireplace_connection#open(arg) abort
let response = client.process({'op': 'eval', 'code': let response = client.process({'op': 'eval', 'code':
\ '(do (println "success") (symbol (str (System/getProperty "path.separator") (System/getProperty "java.class.path"))))'}) \ '(do (println "success") (symbol (str (System/getProperty "path.separator") (System/getProperty "java.class.path"))))'})
let client._path = response.value[-1] let client._path = response.value[-1]
if !has_key(response, 'out') if has_key(response, 'out')
let g:nrepl_fireplace_sessions[client.session] = client
else
unlet client.session unlet client.session
endif endif
return client return client
endfunction endfunction
function! s:nrepl_close() dict abort
if has_key(self, 'session')
try
unlet! g:nrepl_fireplace_sessions[self.session]
call self.call({'op': 'close'})
catch //
finally
unlet self.session
endtry
endif
return self
endfunction
function! s:nrepl_path() dict abort function! s:nrepl_path() dict abort
return split(self._path[1:-1], self._path[0]) return split(self._path[1:-1], self._path[0])
endfunction endfunction
@ -211,6 +237,7 @@ function! s:nrepl_call(payload) dict abort
endfunction endfunction
let s:nrepl = { let s:nrepl = {
\ 'close': s:function('s:nrepl_close'),
\ 'command': s:function('s:nrepl_command'), \ 'command': s:function('s:nrepl_command'),
\ 'dispatch': s:function('s:nrepl_dispatch'), \ 'dispatch': s:function('s:nrepl_dispatch'),
\ 'prepare': s:function('s:nrepl_prepare'), \ 'prepare': s:function('s:nrepl_prepare'),