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
|
if index(combined[key], response[key]) < 0
|
||||||
call extend(combined[key], [response[key]])
|
call extend(combined[key], [response[key]])
|
||||||
endif
|
endif
|
||||||
elseif key ==# 'out' && response.out =~# '^\b.*(.*)$'
|
|
||||||
let combined.stacktrace = split(response.out, "\b")
|
|
||||||
elseif type(response[key]) == type('')
|
elseif type(response[key]) == type('')
|
||||||
let combined[key] = get(combined, key, '') . response[key]
|
let combined[key] = get(combined, key, '') . response[key]
|
||||||
else
|
else
|
||||||
@ -146,10 +144,7 @@ endfunction
|
|||||||
|
|
||||||
function! s:nrepl_eval(expr, ...) dict abort
|
function! s:nrepl_eval(expr, ...) dict abort
|
||||||
let payload = {"op": "eval"}
|
let payload = {"op": "eval"}
|
||||||
let payload.code = '(try (clojure.core/eval ''(do '.a:expr."\n".'))' .
|
let payload.code = a:expr
|
||||||
\ ' (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 options = a:0 ? a:1 : {}
|
let options = a:0 ? a:1 : {}
|
||||||
if has_key(options, 'ns')
|
if has_key(options, 'ns')
|
||||||
let payload.ns = 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"
|
echo "nREPL: server has bug preventing session support"
|
||||||
echohl None
|
echohl None
|
||||||
endif
|
endif
|
||||||
elseif has_key(options, 'file_path')
|
endif
|
||||||
|
if has_key(options, 'file_path')
|
||||||
let payload.op = 'load-file'
|
let payload.op = 'load-file'
|
||||||
let payload['file-path'] = options.file_path
|
let payload['file-path'] = options.file_path
|
||||||
let payload['file-name'] = fnamemodify(options.file_path, ':t')
|
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
|
let self.ns = response.ns
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if has_key(response, 'ex') && has_key(payload, 'session')
|
||||||
|
let response.stacktrace = s:extract_last_stacktrace(self)
|
||||||
|
endif
|
||||||
|
|
||||||
if has_key(response, 'value')
|
if has_key(response, 'value')
|
||||||
let response.value = response.value[-1]
|
let response.value = response.value[-1]
|
||||||
endif
|
endif
|
||||||
return response
|
return response
|
||||||
endfunction
|
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
|
function! s:nrepl_call(payload) dict abort
|
||||||
let in = 'ruby -rsocket -e '.s:shellesc(
|
let in = 'ruby -rsocket -e '.s:shellesc(
|
||||||
\ 'begin;' .
|
\ 'begin;' .
|
||||||
|
@ -526,17 +526,13 @@ function! fireplace#eval(expr, ...) abort
|
|||||||
throw err
|
throw err
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fireplace#session_eval(expr) abort
|
function! fireplace#session_eval(expr, ...) abort
|
||||||
return fireplace#eval(a:expr, {'session': 1})
|
return fireplace#eval(a:expr, extend({'session': 1}, a:0 ? a:1 : {}))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fireplace#echo_session_eval(expr) abort
|
function! fireplace#echo_session_eval(expr, ...) abort
|
||||||
return fireplace#echo_eval(a:expr, {'session': 1})
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! fireplace#echo_eval(expr, options) abort
|
|
||||||
try
|
try
|
||||||
echo fireplace#eval(a:expr, a:options)
|
echo fireplace#session_eval(a:expr, a:0 ? a:1 : {})
|
||||||
catch /^Clojure:/
|
catch /^Clojure:/
|
||||||
endtry
|
endtry
|
||||||
return ''
|
return ''
|
||||||
@ -664,7 +660,6 @@ function! s:Eval(bang, line1, line2, count, args) abort
|
|||||||
let options = {}
|
let options = {}
|
||||||
if a:args !=# ''
|
if a:args !=# ''
|
||||||
let expr = a:args
|
let expr = a:args
|
||||||
let options.session = 1
|
|
||||||
else
|
else
|
||||||
if a:count ==# 0
|
if a:count ==# 0
|
||||||
normal! ^
|
normal! ^
|
||||||
@ -677,7 +672,6 @@ function! s:Eval(bang, line1, line2, count, args) abort
|
|||||||
if !line1 || !line2
|
if !line1 || !line2
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
let options.session = 0
|
|
||||||
let options.file_path = s:buffer_path()
|
let options.file_path = s:buffer_path()
|
||||||
let expr = repeat("\n", line1-1).join(getline(line1, line2), "\n")
|
let expr = repeat("\n", line1-1).join(getline(line1, line2), "\n")
|
||||||
if a:bang
|
if a:bang
|
||||||
@ -697,7 +691,7 @@ function! s:Eval(bang, line1, line2, count, args) abort
|
|||||||
catch /^Clojure:/
|
catch /^Clojure:/
|
||||||
endtry
|
endtry
|
||||||
else
|
else
|
||||||
call fireplace#echo_eval(expr, options)
|
call fireplace#echo_session_eval(expr, options)
|
||||||
endif
|
endif
|
||||||
return ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
Loading…
Reference in New Issue
Block a user