Skip to content

Commit 3a1f14a

Browse files
committed
Reduce blocking
* Use `rpcnotify()`, rather than `rpcrequest()`, since none of our plugin opeerations use the return value. * Plugin sends channel number to neovim as global variable. Previously, we noticed that randomly, the plugin would write a request to its output stream, but the plugin would not notice it. This was due to the use of `rpcrequest()`. If neovim issued a (1) request to the plugin, and the plugin tried to make a (2) request of neovim before responding to request (1), neovim would ignore request (2), because it was blocked. After receiving the response to request (1), and unblocking, presumably request (2) was sitting in some IO buffer, and would not be immediately read by neovim, causing delays.
1 parent 1c5cc5f commit 3a1f14a

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

plugin/socketrepl.vim

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
let s:p_dir = expand('<sfile>:p:h')
22
let g:is_running = 0
3-
let g:channel = -1
3+
let g:nvim_tcp_plugin_channel = 0
44

55
function! StartIfNotRunning()
66
if g:is_running == 0
77
echo 'Starting SocketREPL client...'
88
let jar_file_path = s:p_dir . '/../' . 'socket-repl-plugin-0.1.0-SNAPSHOT-standalone.jar'
9-
let g:channel = rpcstart('stdbuf', ['--input=0', '--output=0', 'java', '-jar', jar_file_path])
9+
call jobstart(['java', '-jar', jar_file_path], {'rpc': v:true})
1010
let g:is_running = 1
1111
endif
1212
endfunction
@@ -18,49 +18,45 @@ function! Connect(host_colon_port)
1818
else
1919
let conn = a:host_colon_port
2020
endif
21-
let res = rpcrequest(g:channel, 'connect', conn)
21+
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'connect', conn)
2222
return res
2323
endfunction
2424
command! -nargs=? Connect call Connect("<args>")
2525

2626
function! EvalBuffer()
2727
call StartIfNotRunning()
2828
ReplLog
29-
let res = rpcrequest(g:channel, 'eval-buffer', [])
29+
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'eval-buffer', [])
3030
return res
3131
endfunction
3232
command! EvalBuffer call EvalBuffer()
3333

3434
function! EvalCode()
3535
call StartIfNotRunning()
3636
ReplLog
37-
let res = rpcrequest(g:channel, 'eval-code', [])
37+
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'eval-code', [])
3838
return res
3939
endfunction
4040
command! EvalCode call EvalCode()
4141

4242
function! ReplLog(buffer_cmd)
4343
call StartIfNotRunning()
44-
let res = rpcrequest(g:channel, 'show-log', a:buffer_cmd)
45-
" Response to no-op will 'flush' plugin -> neovim message 'buffer'
46-
call rpcrequest(g:channel, 'no-op', '')
44+
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'show-log', a:buffer_cmd)
4745
return res
4846
endfunction
4947
command! ReplLog call ReplLog(':botright new')
5048

5149
function! DismissReplLog()
5250
call StartIfNotRunning()
53-
let res = rpcrequest(g:channel, 'dismiss-log', [])
54-
" Response to no-op will 'flush' plugin -> neovim message 'buffer'
55-
call rpcrequest(g:channel, 'no-op', '')
51+
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'dismiss-log', [])
5652
return res
5753
endfunction
5854
command! DismissReplLog call DismissReplLog()
5955

6056
function! Doc()
6157
call StartIfNotRunning()
6258
ReplLog
63-
let res = rpcrequest(g:channel, 'doc', [])
59+
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'doc', [])
6460
return res
6561
endfunction
6662
command! Doc call Doc()

0 commit comments

Comments
 (0)