Skip to content

Commit db81492

Browse files
committed
Add a mapping to restart the babashka auto REPL
1 parent fa0c1f5 commit db81492

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

doc/conjure-client-clojure-nrepl.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ options relevant to these mappings.
143143

144144
<localleader>rc Clear the namespace refresh cache.
145145

146+
<localleader>car Restart the babashka auto-REPL. This will disconnect
147+
the current nREPL connection, stop the babashka
148+
process, and start a fresh one. Your next evaluation
149+
will automatically reconnect.
150+
146151
==============================================================================
147152
CONFIGURATION *conjure-client-clojure-nrepl-configuration*
148153

@@ -492,6 +497,11 @@ All configuration can be set as described in |conjure-configuration|.
492497
Clear the namespace refresh cache.
493498
Default: `rc`
494499

500+
*g:conjure#client#clojure#nrepl#mapping#auto_repl_restart*
501+
`g:conjure#client#clojure#nrepl#mapping#auto_repl_restart`
502+
Restart the babashka auto-REPL.
503+
Default: `car`
504+
495505
*g:conjure#client#clojure#nrepl#completion#cljs#use_suitable*
496506
`g:conjure#client#clojure#nrepl#completion#cljs#use_suitable`
497507
Use `clj-suitable` to improve cljs completion.

fnl/conjure/client/clojure/nrepl/auto-repl.fnl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
(local config (autoload :conjure.config))
55
(local log (autoload :conjure.log))
66
(local process (autoload :conjure.process))
7+
(local server (autoload :conjure.client.clojure.nrepl.server))
78
(local state (autoload :conjure.client.clojure.nrepl.state))
9+
(local vim _G.vim)
810

911
(local M (define :conjure.client.clojure.nrepl.auto-repl))
1012

@@ -53,4 +55,20 @@
5355
(log.append [(.. "; Starting auto-repl: " cmd)])
5456
proc))))
5557

58+
(fn M.stop-auto-repl-proc []
59+
"Stops the auto REPL if running."
60+
(let [proc (state.get :auto-repl-proc)]
61+
(when (process.running? proc)
62+
(process.stop proc)
63+
(M.delete-auto-repl-port-file)
64+
(core.assoc (state.get) :auto-repl-proc nil)
65+
(core.assoc (state.get) :auto-repl-port nil)
66+
(log.append ["; Stopped auto-repl"]))))
67+
68+
(fn M.restart-auto-repl-proc []
69+
"Restarts the auto REPL - disconnects, stops, starts fresh, and reconnects."
70+
(server.disconnect)
71+
(M.stop-auto-repl-proc)
72+
(M.upsert-auto-repl-proc))
73+
5674
M

fnl/conjure/client/clojure/nrepl/init.fnl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@
125125

126126
:refresh_changed "rr"
127127
:refresh_all "ra"
128-
:refresh_clear "rc"}}}}}))
128+
:refresh_clear "rc"
129+
130+
:auto_repl_restart "car"}}}}}))
129131

130132
(fn M.context [header]
131133
(-?> header
@@ -290,6 +292,11 @@
290292
(util.wrap-require-fn-call :conjure.client.clojure.nrepl.action :view-tap)
291293
{:desc "Show all tapped values and clear the queue"})
292294

295+
(mapping.buf
296+
:CljAutoReplRestart (cfg [:mapping :auto_repl_restart])
297+
(util.wrap-require-fn-call :conjure.client.clojure.nrepl.auto-repl :restart-auto-repl-proc)
298+
{:desc "Restart the babashka auto-REPL"})
299+
293300
(vim.api.nvim_buf_create_user_command
294301
0
295302
"ConjureShadowSelect"

lua/conjure/client/clojure/nrepl/auto-repl.lua

Lines changed: 22 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lua/conjure/client/clojure/nrepl/init.lua

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)