Skip to content

Commit 3902004

Browse files
committed
Start plugin async automatically
1 parent 17d15ac commit 3902004

File tree

5 files changed

+81
-23
lines changed

5 files changed

+81
-23
lines changed

TODO

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ TODO alpha
5959

6060
[_] Enhance debugging
6161
[X] Comment new debug script function
62-
[_] [NEXT] Document / video process for debugging, including refresh, restart
62+
[X] Starting plugin should be async, locked, subsequent calls
63+
to start whilie in progress tell you its starting
64+
[X] plugin script has global status var
65+
let g:..._ready = 0
66+
[X] plugin notifies neovim that it is ready
67+
echo "started"
68+
let g:..._ready = 1
69+
[X] plugin script blocks commands until ready
70+
echo "not started"
71+
[X] start the jar on plugin load, unless user disables it by
72+
setting a global var
73+
[X] provide a :Start command to run it manually
74+
[_] Document / video process for debugging, including refresh, restart
6375
and reconnect
6476
[X] debug restart function should close repl log

plugin/socketrepl.vim

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
let s:p_dir = expand('<sfile>:p:h')
22
let g:is_running = 0
3+
let g:socket_repl_plugin_ready = 0
34
let g:nvim_tcp_plugin_channel = 0
45

6+
let s:not_ready = "SocketREPL plugin not ready (starting)"
7+
58
function! StartIfNotRunning()
69
if g:is_running == 0
7-
echo 'Starting SocketREPL client...'
10+
echo 'Starting SocketREPL plugin...'
811
let jar_file_path = s:p_dir . '/../' . 'socket-repl-plugin-0.1.0-SNAPSHOT-standalone.jar'
912
call jobstart(['java', '-jar', jar_file_path], {'rpc': v:true})
1013
let g:is_running = 1
1114
endif
1215
endfunction
16+
command! Start call StartIfNotRunning()
1317

1418
function! Connect(host_colon_port)
15-
call StartIfNotRunning()
1619
if a:host_colon_port == ""
1720
let conn = "localhost:5555"
1821
else
@@ -21,45 +24,88 @@ function! Connect(host_colon_port)
2124
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'connect', conn)
2225
return res
2326
endfunction
24-
command! -nargs=? Connect call Connect("<args>")
27+
28+
function! ReadyConnect(host_colon_port)
29+
if g:socket_repl_plugin_ready == 1
30+
call Connect(a:host_colon_port)
31+
else
32+
echo s:not_ready
33+
endif
34+
endfunction
35+
command! -nargs=? Connect call ReadyConnect("<args>")
2536

2637
function! EvalBuffer()
27-
call StartIfNotRunning()
2838
ReplLog
2939
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'eval-buffer', [])
3040
return res
3141
endfunction
32-
command! EvalBuffer call EvalBuffer()
42+
43+
function! ReadyEvalBuffer()
44+
if g:socket_repl_plugin_ready == 1
45+
call EvalBuffer()
46+
else
47+
echo s:not_ready
48+
endif
49+
endfunction
50+
command! EvalBuffer call ReadyEvalBuffer()
3351

3452
function! EvalCode()
35-
call StartIfNotRunning()
3653
ReplLog
3754
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'eval-code', [])
3855
return res
3956
endfunction
40-
command! EvalCode call EvalCode()
57+
58+
function! ReadyEvalCode()
59+
if g:socket_repl_plugin_ready == 1
60+
call EvalCode()
61+
else
62+
echo s:not_ready
63+
endif
64+
endfunction
65+
command! EvalCode call ReadyEvalCode()
4166

4267
function! ReplLog(buffer_cmd)
43-
call StartIfNotRunning()
4468
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'show-log', a:buffer_cmd)
4569
return res
4670
endfunction
47-
command! ReplLog call ReplLog(':botright new')
71+
72+
function! ReadyReplLog(buffer_cmd)
73+
if g:socket_repl_plugin_ready == 1
74+
call ReplLog(a:buffer_cmd)
75+
else
76+
echo s:not_ready
77+
endif
78+
endfunction
79+
command! ReplLog call ReadyReplLog(':botright new')
4880

4981
function! DismissReplLog()
50-
call StartIfNotRunning()
5182
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'dismiss-log', [])
5283
return res
5384
endfunction
54-
command! DismissReplLog call DismissReplLog()
85+
86+
function! ReadyDismissReplLog()
87+
if g:socket_repl_plugin_ready == 1
88+
call DismissReplLog()
89+
else
90+
echo s:not_ready
91+
endif
92+
endfunction
93+
command! DismissReplLog call ReadyDismissReplLog()
5594

5695
function! Doc()
57-
call StartIfNotRunning()
5896
ReplLog
5997
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'doc', [])
6098
return res
6199
endfunction
62-
command! Doc call Doc()
100+
101+
function! ReadyDoc()
102+
if g:socket_repl_plugin_ready == 1
103+
call Doc()
104+
else
105+
echo s:not_ready
106+
endif
107+
endfunction
108+
command! Doc call ReadyDoc()
63109

64110
if !exists('g:disable_socket_repl_mappings')
65111
nnoremap <leader>eb :EvalBuffer<cr>
@@ -68,3 +114,7 @@ if !exists('g:disable_socket_repl_mappings')
68114
nnoremap <leader>rlog :ReplLog<cr>
69115
nnoremap <leader>drlog :DismissReplLog<cr>
70116
endif
117+
118+
if !exists('g:manually_start_socket_repl_plugin')
119+
call StartIfNotRunning()
120+
endif

plugin/socketrepl.vim.debug

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
let g:nvim_tcp_plugin_channel = 0
22

3-
function! StartIfNotRunning()
4-
endfunction
5-
63
function! Connect(host_colon_port)
7-
call StartIfNotRunning()
84
if a:host_colon_port == ""
95
let conn = "localhost:5555"
106
else
@@ -16,37 +12,32 @@ endfunction
1612
command! -nargs=? Connect call Connect("<args>")
1713

1814
function! EvalBuffer()
19-
call StartIfNotRunning()
2015
ReplLog
2116
let res = rpcrequest(g:nvim_tcp_plugin_channel, 'eval-buffer', [])
2217
return res
2318
endfunction
2419
command! EvalBuffer call EvalBuffer()
2520

2621
function! EvalCode()
27-
call StartIfNotRunning()
2822
ReplLog
2923
let res = rpcrequest(g:nvim_tcp_plugin_channel, 'eval-code', [])
3024
return res
3125
endfunction
3226
command! EvalCode call EvalCode()
3327

3428
function! ReplLog(buffer_cmd)
35-
call StartIfNotRunning()
3629
let res = rpcrequest(g:nvim_tcp_plugin_channel, 'show-log', a:buffer_cmd)
3730
return res
3831
endfunction
3932
command! ReplLog call ReplLog(':botright new')
4033

4134
function! DismissReplLog()
42-
call StartIfNotRunning()
4335
let res = rpcrequest(g:nvim_tcp_plugin_channel, 'dismiss-log', [])
4436
return res
4537
endfunction
4638
command! DismissReplLog call DismissReplLog()
4739

4840
function! Doc()
49-
call StartIfNotRunning()
5041
ReplLog
5142
let res = rpcrequest(g:nvim_tcp_plugin_channel, 'doc', [])
5243
return res
925 Bytes
Binary file not shown.

src/socket_repl/socket_repl_plugin.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@
176176
(fn [msg]
177177
(nvim/vim-command
178178
nvim (format "bd! %s" (get-rlog-buffer-number nvim))))))
179+
180+
(async/thread
181+
(nvim/vim-command nvim "let g:socket_repl_plugin_ready = 1")
182+
(nvim/vim-command nvim "echo 'SocketREPL plugin ready'"))
183+
179184
plugin))
180185

181186
(defn stop

0 commit comments

Comments
 (0)