Different gross hack for extracting backtrace
Now instead of wrapping the code up in a try/catch, we just use a series of evals to grab *e and then restore *1/*2/*3.
This commit is contained in:
parent
fb5c946822
commit
90692edc35
@ -129,8 +129,6 @@ function! s:nrepl_process(payload) dict abort
|
||||
if index(combined[key], response[key]) < 0
|
||||
call extend(combined[key], [response[key]])
|
||||
endif
|
||||
elseif key ==# 'out' && response.out =~# '^\b.*(.*)$'
|
||||
let combined.stacktrace = split(response.out, "\b")
|
||||
elseif type(response[key]) == type('')
|
||||
let combined[key] = get(combined, key, '') . response[key]
|
||||
else
|
||||
@ -146,10 +144,7 @@ endfunction
|
||||
|
||||
function! s:nrepl_eval(expr, ...) dict abort
|
||||
let payload = {"op": "eval"}
|
||||
let payload.code = '(try (clojure.core/eval ''(do '.a:expr."\n".'))' .
|
||||
\ ' (catch Exception e' .
|
||||
\ ' (clojure.core/print (clojure.core/apply clojure.core/str (clojure.core/interleave (clojure.core/repeat "\b") (clojure.core/map clojure.core/str (.getStackTrace e)))))' .
|
||||
\ ' (throw e)))'
|
||||
let payload.code = a:expr
|
||||
let options = a:0 ? a:1 : {}
|
||||
if has_key(options, 'ns')
|
||||
let payload.ns = options.ns
|
||||
@ -164,7 +159,8 @@ function! s:nrepl_eval(expr, ...) dict abort
|
||||
echo "nREPL: server has bug preventing session support"
|
||||
echohl None
|
||||
endif
|
||||
elseif has_key(options, 'file_path')
|
||||
endif
|
||||
if has_key(options, 'file_path')
|
||||
let payload.op = 'load-file'
|
||||
let payload['file-path'] = options.file_path
|
||||
let payload['file-name'] = fnamemodify(options.file_path, ':t')
|
||||
@ -181,12 +177,25 @@ function! s:nrepl_eval(expr, ...) dict abort
|
||||
let self.ns = response.ns
|
||||
endif
|
||||
|
||||
if has_key(response, 'ex') && has_key(payload, 'session')
|
||||
let response.stacktrace = s:extract_last_stacktrace(self)
|
||||
endif
|
||||
|
||||
if has_key(response, 'value')
|
||||
let response.value = response.value[-1]
|
||||
endif
|
||||
return response
|
||||
endfunction
|
||||
|
||||
function! s:extract_last_stacktrace(nrepl)
|
||||
let format_st = '(clojure.core/symbol (clojure.core/str "\n\b" (clojure.core/apply clojure.core/str (clojure.core/interleave (clojure.core/repeat "\n") (clojure.core/map clojure.core/str (.getStackTrace *e)))) "\n\b\n"))'
|
||||
let stacktrace = split(get(split(a:nrepl.process({'op': 'eval', 'code': '['.format_st.' *3 *2 *1]', 'session': a:nrepl.session}).value[0], "\n\b\n"), 1, ""), "\n")
|
||||
call a:nrepl.call({'op': 'eval', 'code': '(nth *1 1)', 'session': a:nrepl.session})
|
||||
call a:nrepl.call({'op': 'eval', 'code': '(nth *2 2)', 'session': a:nrepl.session})
|
||||
call a:nrepl.call({'op': 'eval', 'code': '(nth *3 3)', 'session': a:nrepl.session})
|
||||
return stacktrace
|
||||
endfunction
|
||||
|
||||
function! s:nrepl_call(payload) dict abort
|
||||
let in = 'ruby -rsocket -e '.s:shellesc(
|
||||
\ 'begin;' .
|
||||
|
@ -526,17 +526,13 @@ function! fireplace#eval(expr, ...) abort
|
||||
throw err
|
||||
endfunction
|
||||
|
||||
function! fireplace#session_eval(expr) abort
|
||||
return fireplace#eval(a:expr, {'session': 1})
|
||||
function! fireplace#session_eval(expr, ...) abort
|
||||
return fireplace#eval(a:expr, extend({'session': 1}, a:0 ? a:1 : {}))
|
||||
endfunction
|
||||
|
||||
function! fireplace#echo_session_eval(expr) abort
|
||||
return fireplace#echo_eval(a:expr, {'session': 1})
|
||||
endfunction
|
||||
|
||||
function! fireplace#echo_eval(expr, options) abort
|
||||
function! fireplace#echo_session_eval(expr, ...) abort
|
||||
try
|
||||
echo fireplace#eval(a:expr, a:options)
|
||||
echo fireplace#session_eval(a:expr, a:0 ? a:1 : {})
|
||||
catch /^Clojure:/
|
||||
endtry
|
||||
return ''
|
||||
@ -664,7 +660,6 @@ function! s:Eval(bang, line1, line2, count, args) abort
|
||||
let options = {}
|
||||
if a:args !=# ''
|
||||
let expr = a:args
|
||||
let options.session = 1
|
||||
else
|
||||
if a:count ==# 0
|
||||
normal! ^
|
||||
@ -677,7 +672,6 @@ function! s:Eval(bang, line1, line2, count, args) abort
|
||||
if !line1 || !line2
|
||||
return ''
|
||||
endif
|
||||
let options.session = 0
|
||||
let options.file_path = s:buffer_path()
|
||||
let expr = repeat("\n", line1-1).join(getline(line1, line2), "\n")
|
||||
if a:bang
|
||||
@ -697,7 +691,7 @@ function! s:Eval(bang, line1, line2, count, args) abort
|
||||
catch /^Clojure:/
|
||||
endtry
|
||||
else
|
||||
call fireplace#echo_eval(expr, options)
|
||||
call fireplace#echo_session_eval(expr, options)
|
||||
endif
|
||||
return ''
|
||||
endfunction
|
||||
|
Loading…
Reference in New Issue
Block a user