Skip to content

Commit 760ae04

Browse files
committed
WIP - add repl log buffer
1 parent 294af3d commit 760ae04

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

socket-repl-plugin/plugin/socketrepl.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ function! EvalCode()
3434
endfunction
3535
command! EvalCode call EvalCode()
3636

37+
function! ReplLog()
38+
"call StartIfNotRunning()
39+
let res = rpcrequest(1, 'show-log', [])
40+
return res
41+
endfunction
42+
command! ReplLog call ReplLog()
43+
3744
echo 'socket repl plugin loaded!'

socket-repl-plugin/src/socket_repl/socket_repl_plugin.clj

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939

4040
(defn write-output
4141
"Write a string to the output file."
42-
[{:keys [:file]} string]
43-
(.print file string)
44-
(.flush file))
42+
[{:keys [:file-stream]} string]
43+
(.print file-stream string)
44+
(.flush file-stream))
4545

4646
(defn write-output!
4747
"Like `write-output`, but uses the current socket repl connection."
@@ -56,12 +56,14 @@
5656
`handler` is a function which accepts one string argument."
5757
[host port handler]
5858
(let [conn (connection host port)
59-
chan (async/chan 10)]
59+
chan (async/chan 10)
60+
file (output-file)]
6061
(reset! current-connection
6162
(assoc conn
6263
:handler handler
6364
:chan chan
64-
:file (PrintStream. (output-file))))
65+
:file file
66+
:file-stream (PrintStream. file)))
6567

6668
;; input producer
6769
(go-loop []
@@ -105,6 +107,26 @@
105107
(write-output! (str x "\n"))
106108
(write-code! x)))))
107109

110+
(nvim/register-method!
111+
"show-log"
112+
(fn [msg]
113+
114+
(nvim/run-command-async!
115+
(format ":term tail -f %s" (-> @current-connection
116+
:file
117+
.getAbsolutePath))
118+
(fn [_]))
119+
120+
;; Native solution, but only seems to work when the buffer has focus.
121+
#_(nvim/run-command-async!
122+
(format ":e %s" (-> @current-connection
123+
:file
124+
.getAbsolutePath))
125+
(fn [_]
126+
(nvim/run-command-async!
127+
":set updatetime=500 | au CursorHold <buffer> :e!"
128+
(fn [_] nil))))))
129+
108130
;; TODO: Rather than an arbitrary timeout, the plugin should shut down
109131
;; when it has received no input for some time.
110132
(comment

0 commit comments

Comments
 (0)