Skip to content

Commit 9ed3904

Browse files
committed
Merge branch 'pyrmont-feature.janet-netrepl-info' into develop
2 parents 64eaf6d + cf2964c commit 9ed3904

File tree

4 files changed

+53
-32
lines changed

4 files changed

+53
-32
lines changed

fnl/conjure/client/janet/netrepl.fnl

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

51-
(defn- send [msg cb]
52-
(with-conn-or-warn
53-
(fn [conn]
54-
(remote.send conn msg cb))))
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)))))
5558

5659
(defn connect [opts]
5760
(let [opts (or opts {})
@@ -89,15 +92,18 @@
8992
(defn eval-str [opts]
9093
(try-ensure-conn)
9194
(send
92-
(.. opts.code "\n")
93-
(fn [msg]
94-
(let [clean (text.trim-last-newline msg)]
95-
(when opts.on-result
96-
;; ANSI escape trimming happens here AND in log append (if enabled)
97-
;; so that "eval and replace form" won't end up inserting ANSI codes.
98-
(opts.on-result (text.strip-ansi-escape-sequences clean)))
99-
(when (not opts.passive?)
100-
(log.append (text.split-lines clean)))))))
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}))
101107

102108
(defn doc-str [opts]
103109
(try-ensure-conn)

fnl/conjure/remote/netrepl.fnl

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
client conjure.client
66
trn conjure.remote.transport.netrepl}})
77

8-
(defn send [conn msg cb]
9-
"Send a message to the given connection, call the callback when a response is received."
8+
(defn send [conn msg cb prompt?]
9+
"Send a message to the given connection, call the callback when a response is received.
10+
If a prompt is expected in addition to the response, prompt? should be set to true."
1011
(log.dbg "send" msg)
1112
(table.insert conn.queue 1 (or cb false))
13+
(when prompt?
14+
(table.insert conn.queue 1 false))
1215
(conn.sock:write (trn.encode msg))
1316
nil)
1417

lua/conjure/client/janet/netrepl.lua

+20-12
Original file line numberDiff line numberDiff line change
@@ -65,11 +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)
69-
local function _6_(conn)
70-
return remote.send(conn, msg, cb)
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)
76+
remote.send(conn, ("\255(parser/where (dyn :parser) " .. row .. " " .. col .. ")"))
77+
remote.send(conn, ("\254source \"" .. file_path .. "\""), nil, true)
78+
return remote.send(conn, msg, cb, true)
7179
end
72-
return with_conn_or_warn(_6_)
80+
return with_conn_or_warn(_7_)
7381
end
7482
_2amodule_locals_2a["send"] = send
7583
local function connect(opts)
@@ -80,21 +88,21 @@ local function connect(opts)
8088
disconnect()
8189
else
8290
end
83-
local function _8_(err)
91+
local function _9_(err)
8492
display_conn_status(err)
8593
return disconnect()
8694
end
87-
local function _9_()
95+
local function _10_()
8896
return display_conn_status("connected")
8997
end
90-
local function _10_(err)
98+
local function _11_(err)
9199
if err then
92100
return display_conn_status(err)
93101
else
94102
return disconnect()
95103
end
96104
end
97-
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_}))
98106
end
99107
_2amodule_2a["connect"] = connect
100108
local function try_ensure_conn()
@@ -107,7 +115,7 @@ end
107115
_2amodule_locals_2a["try-ensure-conn"] = try_ensure_conn
108116
local function eval_str(opts)
109117
try_ensure_conn()
110-
local function _13_(msg)
118+
local function _14_(msg)
111119
local clean = text["trim-last-newline"](msg)
112120
if opts["on-result"] then
113121
opts["on-result"](text["strip-ansi-escape-sequences"](clean))
@@ -119,15 +127,15 @@ local function eval_str(opts)
119127
return nil
120128
end
121129
end
122-
return send((opts.code .. "\n"), _13_)
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"]})
123131
end
124132
_2amodule_2a["eval-str"] = eval_str
125133
local function doc_str(opts)
126134
try_ensure_conn()
127-
local function _16_(_241)
135+
local function _17_(_241)
128136
return ("(doc " .. _241 .. ")")
129137
end
130-
return eval_str(a.update(opts, "code", _16_))
138+
return eval_str(a.update(opts, "code", _17_))
131139
end
132140
_2amodule_2a["doc-str"] = doc_str
133141
local function eval_file(opts)

lua/conjure/remote/netrepl.lua

+9-5
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ _2amodule_locals_2a["client"] = client
1717
_2amodule_locals_2a["log"] = log
1818
_2amodule_locals_2a["net"] = net
1919
_2amodule_locals_2a["trn"] = trn
20-
local function send(conn, msg, cb)
20+
local function send(conn, msg, cb, prompt_3f)
2121
log.dbg("send", msg)
2222
table.insert(conn.queue, 1, (cb or false))
23+
if prompt_3f then
24+
table.insert(conn.queue, 1, false)
25+
else
26+
end
2327
do end (conn.sock):write(trn.encode(msg))
2428
return nil
2529
end
@@ -30,7 +34,7 @@ local function connect(opts)
3034
if (err or not chunk) then
3135
return opts["on-error"](err)
3236
else
33-
local function _1_(msg)
37+
local function _2_(msg)
3438
log.dbg("receive", msg)
3539
local cb = table.remove(conn.queue)
3640
if cb then
@@ -39,18 +43,18 @@ local function connect(opts)
3943
return nil
4044
end
4145
end
42-
return a["run!"](_1_, conn.decode(chunk))
46+
return a["run!"](_2_, conn.decode(chunk))
4347
end
4448
end
45-
local function _4_(err)
49+
local function _5_(err)
4650
if err then
4751
return opts["on-failure"](err)
4852
else
4953
do end (conn.sock):read_start(client["schedule-wrap"](handle_message))
5054
return opts["on-success"]()
5155
end
5256
end
53-
conn = a.merge(conn, net.connect({host = opts.host, port = opts.port, cb = client["schedule-wrap"](_4_)}))
57+
conn = a.merge(conn, net.connect({host = opts.host, port = opts.port, cb = client["schedule-wrap"](_5_)}))
5458
send(conn, (opts.name or "Conjure"))
5559
return conn
5660
end

0 commit comments

Comments
 (0)