@@ -6,6 +6,8 @@ if exists("g:autoloaded_nrepl_fireplace_connection") || &cp
6
6
endif
7
7
let g: autoloaded_nrepl_fireplace_connection = 1
8
8
9
+ let s: python_dir = fnamemodify (expand (" <sfile>" ), ' :p:h:h:h' ) . ' /python'
10
+
9
11
function ! s: function (name) abort
10
12
return function (substitute (a: name ,' ^s:' ,matchstr (expand (' <sfile>' ), ' <SNR>\d\+_' ),' ' ))
11
13
endfunction
@@ -197,22 +199,16 @@ function! s:extract_last_stacktrace(nrepl)
197
199
endfunction
198
200
199
201
function ! s: nrepl_call (payload) dict abort
200
- let in = ' ruby -rsocket -e ' .s: shellesc (
201
- \ ' begin;' .
202
- \ ' TCPSocket.open(%(' . self .host . ' ), ' . self .port . ' ) {|s|' .
203
- \ ' s.write(ARGV.first); loop {' .
204
- \ ' body = s.readpartial(8192);' .
205
- \ ' raise %(not an nREPL server: upgrade to Leiningen 2) if body =~ /=> $/;' .
206
- \ ' print body;' .
207
- \ ' break if body =~ /6:statusl(5:error|14:session-closed)?4:done/ }};' .
208
- \ ' rescue; abort $!.to_s;' .
209
- \ ' end' ) . ' ' .
210
- \ s: shellesc (nrepl#fireplace_connection#bencode (a: payload ))
202
+ let in = ' python'
203
+ \ . ' ' . s: shellesc (s: python_dir .' /nrepl_fireplace.py' )
204
+ \ . ' ' . s: shellesc (self .host)
205
+ \ . ' ' . s: shellesc (self .port)
206
+ \ . ' ' . s: shellesc (nrepl#fireplace_connection#bencode (a: payload ))
211
207
let out = system (in )
212
208
if ! v: shell_error
213
209
return nrepl#fireplace_connection#bdecode (' l' .out.' e' )
214
210
endif
215
- throw ' nREPL: ' .split ( out, " \n " )[ 0 ]
211
+ throw ' nREPL: ' .out
216
212
endfunction
217
213
218
214
let s: nrepl = {
@@ -225,12 +221,16 @@ if !has('python')
225
221
finish
226
222
endif
227
223
224
+ if ! exists (' s:python' )
225
+ exe ' python sys.path.insert(0, "' .s: python_dir .' ")'
226
+ let s: python = 1
227
+ python import nrepl_fireplace
228
+ else
229
+ python reload (nrepl_fireplace)
230
+ endif
231
+
228
232
python << EOF
229
233
import vim
230
- import select
231
- import socket
232
- import string
233
- import re
234
234
235
235
def fireplace_string_encode (input ):
236
236
str_list = []
@@ -244,38 +244,19 @@ def fireplace_string_encode(input):
244
244
def fireplace_let (var , value):
245
245
return vim .command (' let ' + var + " = " + fireplace_string_encode (value))
246
246
247
+ def fireplace_check ():
248
+ vim .eval (' getchar(1)' )
249
+
247
250
def fireplace_repl_interact ():
248
- buffer = ' '
249
- s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
250
- host = vim .eval (' self.host' )
251
- port = int (vim .eval (' self.port' ))
252
- s .settimeout (8 )
253
251
try :
254
- try :
255
- s .connect ((host, port))
256
- s .setblocking (1 )
257
- s .sendall (vim .eval (' payload' ))
258
- while True:
259
- while len (select.select ([s ], [], [], 0.1 )[0 ]) == 0 :
260
- vim .eval (' getchar(1)' )
261
- body = s .recv (8192 )
262
- if re .search (" => $" , body) != None:
263
- raise Exception (" not an nREPL server: upgrade to Leiningen 2" )
264
- buffer += body
265
- if re .search (' 6:statusl(5:error|14:session-closed)?4:done' , body):
266
- break
267
- fireplace_let (' out' , buffer )
268
- except Exception , e :
269
- fireplace_let (' err' , str (e ))
270
- finally :
271
- s .close ()
252
+ fireplace_let (' out' , nrepl_fireplace.repl_send (vim .eval (' self.host' ), int (vim .eval (' self.port' )), vim .eval (' payload' ), fireplace_check))
253
+ except Exception , e :
254
+ fireplace_let (' err' , str (e ))
272
255
EOF
273
256
274
257
function ! s: nrepl_call (payload) dict abort
275
258
let payload = nrepl#fireplace_connection#bencode (a: payload )
276
- python << EOF
277
- fireplace_repl_interact ()
278
- EOF
259
+ python fireplace_repl_interact ()
279
260
if ! exists (' err' )
280
261
return nrepl#fireplace_connection#bdecode (' l' .out.' e' )
281
262
endif
0 commit comments