Reimplement nrepl/combine-responses
This commit is contained in:
parent
53bd402662
commit
5b42ed5c65
@ -97,11 +97,11 @@ function! nrepl#foreplay_connection#open(arg) abort
|
|||||||
let client = deepcopy(s:nrepl)
|
let client = deepcopy(s:nrepl)
|
||||||
let client.host = host
|
let client.host = host
|
||||||
let client.port = port
|
let client.port = port
|
||||||
let session = client.call({'op': 'clone'})[0]['new-session']
|
let session = client.process({'op': 'clone'})['new-session']
|
||||||
let response = client.call({'op': 'eval', 'session': session, 'code':
|
let response = client.process({'op': 'eval', 'session': session, '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[-2]['value']
|
let client._path = response.value
|
||||||
if len(response) == 3
|
if has_key(response, 'out')
|
||||||
let client.session = session
|
let client.session = session
|
||||||
endif
|
endif
|
||||||
return client
|
return client
|
||||||
@ -112,25 +112,34 @@ function! s:nrepl_path() dict abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:nrepl_process(payload) dict abort
|
function! s:nrepl_process(payload) dict abort
|
||||||
let parsed = self.call(a:payload)
|
let combined = {'status': [], 'session': []}
|
||||||
let result = {}
|
for response in self.call(a:payload)
|
||||||
for packet in parsed
|
for key in keys(response)
|
||||||
if has_key(packet, 'out')
|
if key ==# 'id' || key ==# 'ns'
|
||||||
echo substitute(packet.out, '\n$', '', '')
|
let combined[key] = response[key]
|
||||||
endif
|
elseif key ==# 'value'
|
||||||
if has_key(packet, 'err')
|
let combined.value = extend(get(combined, 'value', []), [response.value])
|
||||||
echohl ErrorMSG
|
elseif key ==# 'status'
|
||||||
echo substitute(packet.err, '\n$', '', '')
|
for entry in response[key]
|
||||||
echohl NONE
|
if index(combined[key], entry) < 0
|
||||||
endif
|
call extend(combined[key], [entry])
|
||||||
if has_key(packet, 'status') && index(packet.status, 'error') >= 0
|
endif
|
||||||
throw 'nREPL: ' . tr(packet.status[0], '-', ' ')
|
endfor
|
||||||
endif
|
elseif key ==# 'session'
|
||||||
if has_key(packet, 'ex') || has_key(packet, 'value')
|
if index(combined[key], response[key]) < 0
|
||||||
let result = packet
|
call extend(combined[key], [response[key]])
|
||||||
endif
|
endif
|
||||||
|
elseif type(response[key]) == type('')
|
||||||
|
let combined[key] = get(combined, key, '') . response[key]
|
||||||
|
else
|
||||||
|
let combined[key] = response[key]
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
endfor
|
endfor
|
||||||
return result
|
if index(combined.status, 'error') >= 0
|
||||||
|
throw 'nREPL: ' . tr(combined.status[0], '-', ' ')
|
||||||
|
endif
|
||||||
|
return combined
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:nrepl_eval(expr, ...) dict abort
|
function! s:nrepl_eval(expr, ...) dict abort
|
||||||
@ -143,16 +152,26 @@ function! s:nrepl_eval(expr, ...) dict abort
|
|||||||
if has_key(self, 'session')
|
if has_key(self, 'session')
|
||||||
let payload.session = self.session
|
let payload.session = self.session
|
||||||
endif
|
endif
|
||||||
let packet = self.process(payload)
|
let response = self.process(payload)
|
||||||
if has_key(packet, 'value')
|
if has_key(response, 'ns') && !a:0
|
||||||
if !a:0
|
let self.ns = response.ns
|
||||||
let self.ns = packet.ns
|
endif
|
||||||
endif
|
|
||||||
return packet.value
|
if has_key(response, 'err')
|
||||||
elseif has_key(packet, 'ex')
|
echohl ErrorMSG
|
||||||
let err = 'Clojure: '.packet.ex
|
echo substitute(response.err, '\n$', '', '')
|
||||||
|
echohl NONE
|
||||||
|
endif
|
||||||
|
if has_key(response, 'out')
|
||||||
|
echo substitute(response.out, '\n$', '', '')
|
||||||
|
endif
|
||||||
|
|
||||||
|
if has_key(response, 'ex')
|
||||||
|
let err = 'Clojure: '.response.ex
|
||||||
|
elseif has_key(response, 'value')
|
||||||
|
return response.value[-1]
|
||||||
else
|
else
|
||||||
let err = 'nREPL: '.string(packet)
|
let err = 'nREPL: Unrecognized response '.string(response)
|
||||||
endif
|
endif
|
||||||
throw err
|
throw err
|
||||||
endfunction
|
endfunction
|
||||||
|
Loading…
Reference in New Issue
Block a user