Skip to content

Commit cf2964c

Browse files
committed
Group Janet send args into a table
1 parent c068f72 commit cf2964c

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

fnl/conjure/client/janet/netrepl.fnl

+19-18
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@
4848
(display-conn-status :disconnected)
4949
(a.assoc (state) :conn nil))))
5050

51-
(defn- send [msg cb row col file-path]
52-
(with-conn-or-warn
53-
(fn [conn]
54-
(remote.send conn (.. "\xFF(parser/where (dyn :parser) " row " " col ")"))
55-
(remote.send conn (.. "\xFEsource \"" file-path "\"") nil true)
56-
(remote.send conn msg cb true))))
51+
(defn- send [opts]
52+
(let [{: msg : cb : row : col : file-path} opts]
53+
(with-conn-or-warn
54+
(fn [conn]
55+
(remote.send conn (.. "\xFF(parser/where (dyn :parser) " row " " col ")"))
56+
(remote.send conn (.. "\xFEsource \"" file-path "\"") nil true)
57+
(remote.send conn msg cb true)))))
5758

5859
(defn connect [opts]
5960
(let [opts (or opts {})
@@ -91,18 +92,18 @@
9192
(defn eval-str [opts]
9293
(try-ensure-conn)
9394
(send
94-
(.. opts.code "\n")
95-
(fn [msg]
96-
(let [clean (text.trim-last-newline msg)]
97-
(when opts.on-result
98-
;; ANSI escape trimming happens here AND in log append (if enabled)
99-
;; so that "eval and replace form" won't end up inserting ANSI codes.
100-
(opts.on-result (text.strip-ansi-escape-sequences clean)))
101-
(when (not opts.passive?)
102-
(log.append (text.split-lines clean)))))
103-
(or (a.get-in opts.range [:start 1]) 1)
104-
(or (a.get-in opts.range [:start 2]) 1)
105-
opts.file-path))
95+
{:msg (.. opts.code "\n")
96+
:cb (fn [msg]
97+
(let [clean (text.trim-last-newline msg)]
98+
(when opts.on-result
99+
;; ANSI escape trimming happens here AND in log append (if enabled)
100+
;; so that "eval and replace form" won't end up inserting ANSI codes.
101+
(opts.on-result (text.strip-ansi-escape-sequences clean)))
102+
(when (not opts.passive?)
103+
(log.append (text.split-lines clean)))))
104+
:row (a.get-in opts.range [:start 1] 1)
105+
:col (a.get-in opts.range [:start 2] 1)
106+
:file-path opts.file-path}))
106107

107108
(defn doc-str [opts]
108109
(try-ensure-conn)

lua/conjure/client/janet/netrepl.lua

+17-11
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,19 @@ local function disconnect()
6565
return with_conn_or_warn(_5_)
6666
end
6767
_2amodule_2a["disconnect"] = disconnect
68-
local function send(msg, cb, row, col, file_path)
69-
local function _6_(conn)
68+
local function send(opts)
69+
local _let_6_ = opts
70+
local msg = _let_6_["msg"]
71+
local cb = _let_6_["cb"]
72+
local row = _let_6_["row"]
73+
local col = _let_6_["col"]
74+
local file_path = _let_6_["file-path"]
75+
local function _7_(conn)
7076
remote.send(conn, ("\255(parser/where (dyn :parser) " .. row .. " " .. col .. ")"))
7177
remote.send(conn, ("\254source \"" .. file_path .. "\""), nil, true)
7278
return remote.send(conn, msg, cb, true)
7379
end
74-
return with_conn_or_warn(_6_)
80+
return with_conn_or_warn(_7_)
7581
end
7682
_2amodule_locals_2a["send"] = send
7783
local function connect(opts)
@@ -82,21 +88,21 @@ local function connect(opts)
8288
disconnect()
8389
else
8490
end
85-
local function _8_(err)
91+
local function _9_(err)
8692
display_conn_status(err)
8793
return disconnect()
8894
end
89-
local function _9_()
95+
local function _10_()
9096
return display_conn_status("connected")
9197
end
92-
local function _10_(err)
98+
local function _11_(err)
9399
if err then
94100
return display_conn_status(err)
95101
else
96102
return disconnect()
97103
end
98104
end
99-
return a.assoc(state(), "conn", remote.connect({host = host, port = port, ["on-failure"] = _8_, ["on-success"] = _9_, ["on-error"] = _10_}))
105+
return a.assoc(state(), "conn", remote.connect({host = host, port = port, ["on-failure"] = _9_, ["on-success"] = _10_, ["on-error"] = _11_}))
100106
end
101107
_2amodule_2a["connect"] = connect
102108
local function try_ensure_conn()
@@ -109,7 +115,7 @@ end
109115
_2amodule_locals_2a["try-ensure-conn"] = try_ensure_conn
110116
local function eval_str(opts)
111117
try_ensure_conn()
112-
local function _13_(msg)
118+
local function _14_(msg)
113119
local clean = text["trim-last-newline"](msg)
114120
if opts["on-result"] then
115121
opts["on-result"](text["strip-ansi-escape-sequences"](clean))
@@ -121,15 +127,15 @@ local function eval_str(opts)
121127
return nil
122128
end
123129
end
124-
return send((opts.code .. "\n"), _13_, (a["get-in"](opts.range, {"start", 1}) or 1), (a["get-in"](opts.range, {"start", 2}) or 1), opts["file-path"])
130+
return send({msg = (opts.code .. "\n"), cb = _14_, row = a["get-in"](opts.range, {"start", 1}, 1), col = a["get-in"](opts.range, {"start", 2}, 1), ["file-path"] = opts["file-path"]})
125131
end
126132
_2amodule_2a["eval-str"] = eval_str
127133
local function doc_str(opts)
128134
try_ensure_conn()
129-
local function _16_(_241)
135+
local function _17_(_241)
130136
return ("(doc " .. _241 .. ")")
131137
end
132-
return eval_str(a.update(opts, "code", _16_))
138+
return eval_str(a.update(opts, "code", _17_))
133139
end
134140
_2amodule_2a["doc-str"] = doc_str
135141
local function eval_file(opts)

0 commit comments

Comments
 (0)