Skip to content

Commit

Permalink
Merge branch 'pyrmont-feature.janet-netrepl-info' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Olical committed Nov 14, 2021
2 parents 64eaf6d + cf2964c commit 9ed3904
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 32 deletions.
32 changes: 19 additions & 13 deletions fnl/conjure/client/janet/netrepl.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@
(display-conn-status :disconnected)
(a.assoc (state) :conn nil))))

(defn- send [msg cb]
(with-conn-or-warn
(fn [conn]
(remote.send conn msg cb))))
(defn- send [opts]
(let [{: msg : cb : row : col : file-path} opts]
(with-conn-or-warn
(fn [conn]
(remote.send conn (.. "\xFF(parser/where (dyn :parser) " row " " col ")"))
(remote.send conn (.. "\xFEsource \"" file-path "\"") nil true)
(remote.send conn msg cb true)))))

(defn connect [opts]
(let [opts (or opts {})
Expand Down Expand Up @@ -89,15 +92,18 @@
(defn eval-str [opts]
(try-ensure-conn)
(send
(.. opts.code "\n")
(fn [msg]
(let [clean (text.trim-last-newline msg)]
(when opts.on-result
;; ANSI escape trimming happens here AND in log append (if enabled)
;; so that "eval and replace form" won't end up inserting ANSI codes.
(opts.on-result (text.strip-ansi-escape-sequences clean)))
(when (not opts.passive?)
(log.append (text.split-lines clean)))))))
{:msg (.. opts.code "\n")
:cb (fn [msg]
(let [clean (text.trim-last-newline msg)]
(when opts.on-result
;; ANSI escape trimming happens here AND in log append (if enabled)
;; so that "eval and replace form" won't end up inserting ANSI codes.
(opts.on-result (text.strip-ansi-escape-sequences clean)))
(when (not opts.passive?)
(log.append (text.split-lines clean)))))
:row (a.get-in opts.range [:start 1] 1)
:col (a.get-in opts.range [:start 2] 1)
:file-path opts.file-path}))

(defn doc-str [opts]
(try-ensure-conn)
Expand Down
7 changes: 5 additions & 2 deletions fnl/conjure/remote/netrepl.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
client conjure.client
trn conjure.remote.transport.netrepl}})

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

Expand Down
32 changes: 20 additions & 12 deletions lua/conjure/client/janet/netrepl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,19 @@ local function disconnect()
return with_conn_or_warn(_5_)
end
_2amodule_2a["disconnect"] = disconnect
local function send(msg, cb)
local function _6_(conn)
return remote.send(conn, msg, cb)
local function send(opts)
local _let_6_ = opts
local msg = _let_6_["msg"]
local cb = _let_6_["cb"]
local row = _let_6_["row"]
local col = _let_6_["col"]
local file_path = _let_6_["file-path"]
local function _7_(conn)
remote.send(conn, ("\255(parser/where (dyn :parser) " .. row .. " " .. col .. ")"))
remote.send(conn, ("\254source \"" .. file_path .. "\""), nil, true)
return remote.send(conn, msg, cb, true)
end
return with_conn_or_warn(_6_)
return with_conn_or_warn(_7_)
end
_2amodule_locals_2a["send"] = send
local function connect(opts)
Expand All @@ -80,21 +88,21 @@ local function connect(opts)
disconnect()
else
end
local function _8_(err)
local function _9_(err)
display_conn_status(err)
return disconnect()
end
local function _9_()
local function _10_()
return display_conn_status("connected")
end
local function _10_(err)
local function _11_(err)
if err then
return display_conn_status(err)
else
return disconnect()
end
end
return a.assoc(state(), "conn", remote.connect({host = host, port = port, ["on-failure"] = _8_, ["on-success"] = _9_, ["on-error"] = _10_}))
return a.assoc(state(), "conn", remote.connect({host = host, port = port, ["on-failure"] = _9_, ["on-success"] = _10_, ["on-error"] = _11_}))
end
_2amodule_2a["connect"] = connect
local function try_ensure_conn()
Expand All @@ -107,7 +115,7 @@ end
_2amodule_locals_2a["try-ensure-conn"] = try_ensure_conn
local function eval_str(opts)
try_ensure_conn()
local function _13_(msg)
local function _14_(msg)
local clean = text["trim-last-newline"](msg)
if opts["on-result"] then
opts["on-result"](text["strip-ansi-escape-sequences"](clean))
Expand All @@ -119,15 +127,15 @@ local function eval_str(opts)
return nil
end
end
return send((opts.code .. "\n"), _13_)
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"]})
end
_2amodule_2a["eval-str"] = eval_str
local function doc_str(opts)
try_ensure_conn()
local function _16_(_241)
local function _17_(_241)
return ("(doc " .. _241 .. ")")
end
return eval_str(a.update(opts, "code", _16_))
return eval_str(a.update(opts, "code", _17_))
end
_2amodule_2a["doc-str"] = doc_str
local function eval_file(opts)
Expand Down
14 changes: 9 additions & 5 deletions lua/conjure/remote/netrepl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ _2amodule_locals_2a["client"] = client
_2amodule_locals_2a["log"] = log
_2amodule_locals_2a["net"] = net
_2amodule_locals_2a["trn"] = trn
local function send(conn, msg, cb)
local function send(conn, msg, cb, prompt_3f)
log.dbg("send", msg)
table.insert(conn.queue, 1, (cb or false))
if prompt_3f then
table.insert(conn.queue, 1, false)
else
end
do end (conn.sock):write(trn.encode(msg))
return nil
end
Expand All @@ -30,7 +34,7 @@ local function connect(opts)
if (err or not chunk) then
return opts["on-error"](err)
else
local function _1_(msg)
local function _2_(msg)
log.dbg("receive", msg)
local cb = table.remove(conn.queue)
if cb then
Expand All @@ -39,18 +43,18 @@ local function connect(opts)
return nil
end
end
return a["run!"](_1_, conn.decode(chunk))
return a["run!"](_2_, conn.decode(chunk))
end
end
local function _4_(err)
local function _5_(err)
if err then
return opts["on-failure"](err)
else
do end (conn.sock):read_start(client["schedule-wrap"](handle_message))
return opts["on-success"]()
end
end
conn = a.merge(conn, net.connect({host = opts.host, port = opts.port, cb = client["schedule-wrap"](_4_)}))
conn = a.merge(conn, net.connect({host = opts.host, port = opts.port, cb = client["schedule-wrap"](_5_)}))
send(conn, (opts.name or "Conjure"))
return conn
end
Expand Down

0 comments on commit 9ed3904

Please sign in to comment.