Support .nrepl-port outside of Leiningen
This commit is contained in:
parent
1bfb5aadcf
commit
ab5eee34d8
@ -134,6 +134,7 @@ let s:repl = {"requires": {}}
|
||||
if !exists('s:repls')
|
||||
let s:repls = []
|
||||
let s:repl_paths = {}
|
||||
let s:repl_portfiles = {}
|
||||
endif
|
||||
|
||||
function! s:repl.user_ns() abort
|
||||
@ -236,6 +237,34 @@ 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')
|
||||
call filter(s:repl_portfiles, 'v:val.connection.transport isnot# a:conn.transport')
|
||||
endfunction
|
||||
|
||||
function! s:register_portfile(portfile, ...) abort
|
||||
let old = get(s:repl_portfiles, a:portfile, {})
|
||||
if has_key(old, 'time') && getftime(a:portfile) !=# old.time
|
||||
call s:unregister_connection(old.connection)
|
||||
let old = {}
|
||||
endif
|
||||
if empty(old) && getfsize(a:portfile) > 0
|
||||
let port = matchstr(readfile(a:portfile, 'b', 1)[0], '\d\+')
|
||||
let s:repl_portfiles[a:portfile] = {'time': getftime(a:portfile)}
|
||||
try
|
||||
let conn = nrepl#fireplace_connection#open(port)
|
||||
let s:repl_portfiles[a:portfile].connection = conn
|
||||
call s:register_connection(conn, a:0 ? a:1 : '')
|
||||
return conn
|
||||
catch /^nREPL Connection Error:/
|
||||
if &verbose
|
||||
echohl WarningMSG
|
||||
echomsg v:exception
|
||||
echohl None
|
||||
endif
|
||||
return {}
|
||||
endtry
|
||||
else
|
||||
return get(old, 'connection', {})
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
@ -437,7 +466,18 @@ function! fireplace#path(...) abort
|
||||
endfunction
|
||||
|
||||
function! fireplace#platform(...) abort
|
||||
for [k, v] in items(s:repl_portfiles)
|
||||
if getftime(k) != v.time
|
||||
call s:unregister_connection(v.connection)
|
||||
endif
|
||||
endfor
|
||||
|
||||
let portfile = findfile('.nrepl-port', '.;/')
|
||||
if !empty(portfile)
|
||||
call s:register_portfile(portfile, fnamemodify(portfile, ':h'))
|
||||
endif
|
||||
silent doautocmd User FireplacePreConnect
|
||||
|
||||
let buf = a:0 ? a:1 : s:buf()
|
||||
let root = simplify(fnamemodify(bufname(buf), ':p:s?[\/]$??'))
|
||||
let previous = ""
|
||||
@ -1320,13 +1360,13 @@ if !exists('s:leiningen_repls')
|
||||
let s:leiningen_paths = {}
|
||||
endif
|
||||
|
||||
function! s:portfile() abort
|
||||
function! s:leiningen_portfile() abort
|
||||
if !exists('b:leiningen_root')
|
||||
return ''
|
||||
endif
|
||||
|
||||
let root = b:leiningen_root
|
||||
let portfiles = [root.'/target/repl-port', root.'/target/repl/repl-port', root.'/.nrepl-port']
|
||||
let portfiles = [root.'/.nrepl-port', root.'/target/repl-port', root.'/target/repl/repl-port']
|
||||
|
||||
for f in portfiles
|
||||
if filereadable(f)
|
||||
@ -1336,7 +1376,6 @@ function! s:portfile() abort
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:leiningen_connect() abort
|
||||
for [k, v] in items(s:leiningen_repls)
|
||||
if getfsize(v.file) <= 0
|
||||
@ -1345,26 +1384,13 @@ function! s:leiningen_connect() abort
|
||||
endif
|
||||
endfor
|
||||
|
||||
let portfile = s:portfile()
|
||||
let portfile = s:leiningen_portfile()
|
||||
if empty(portfile)
|
||||
return
|
||||
endif
|
||||
|
||||
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 s:leiningen_repls[b:leiningen_root] = {'time': getftime(portfile), 'file': portfile}
|
||||
try
|
||||
let conn = nrepl#fireplace_connection#open(port)
|
||||
let s:leiningen_repls[b:leiningen_root].connection = conn
|
||||
call s:register_connection(conn, b:leiningen_root)
|
||||
let s:leiningen_paths[b:leiningen_root] = conn.path()
|
||||
catch /^nREPL Connection Error:/
|
||||
if &verbose
|
||||
echohl WarningMSG
|
||||
echomsg v:exception
|
||||
echohl None
|
||||
endif
|
||||
endtry
|
||||
let conn = s:register_portfile(portfile, b:leiningen_root)
|
||||
if has_key(conn, 'path')
|
||||
let s:leiningen_paths[b:leiningen_root] = conn.path()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user