From cf879c0722d78203144b15e52b4491fd13c04a65 Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Tue, 27 Aug 2024 11:42:39 -1000 Subject: [PATCH 01/13] Convert snd-s7 client --- fnl/conjure/client/snd-s7/stdio.fnl | 82 +++++++++++--------- lua/conjure/client/snd-s7/stdio.lua | 112 ++++++++-------------------- 2 files changed, 79 insertions(+), 115 deletions(-) diff --git a/fnl/conjure/client/snd-s7/stdio.fnl b/fnl/conjure/client/snd-s7/stdio.fnl index 92824c24..052d9261 100644 --- a/fnl/conjure/client/snd-s7/stdio.fnl +++ b/fnl/conjure/client/snd-s7/stdio.fnl @@ -1,4 +1,15 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local nvim (autoload :conjure.aniseed.nvim)) +(local str (autoload :conjure.aniseed.string)) +(local client (autoload :conjure.client)) +(local log (autoload :conjure.log)) +(local stdio (autoload :conjure.remote.stdio-rt)) +(local config (autoload :conjure.config)) +(local mapping (autoload :conjure.mapping)) +(local ts (autoload :conjure.tree-sitter)) + +(import-macros {: augroup : autocmd} :conjure.macros) ;;------------------------------------------------------------ ;; A client for snd/s7 (sound editor with s7 scheme scripting) @@ -17,18 +28,6 @@ ;; ;;------------------------------------------------------------ -(module conjure.client.snd-s7.stdio - {autoload {a conjure.aniseed.core - str conjure.aniseed.string - nvim conjure.aniseed.nvim - stdio conjure.remote.stdio-rt - config conjure.config - mapping conjure.mapping - client conjure.client - log conjure.log - ts conjure.tree-sitter} - require-macros [conjure.macros]}) - (config.merge {:client {:snd-s7 @@ -45,37 +44,35 @@ :stop "cS" :interrupt "ei"}}}}})) -(def- cfg (config.get-in-fn [:client :snd-s7 :stdio])) - -(defonce- state (client.new-state #(do {:repl nil}))) - -(def buf-suffix ".scm") -(def comment-prefix "; ") -(def form-node? ts.node-surrounded-by-form-pair-chars?) +(local cfg (config.get-in-fn [:client :snd-s7 :stdio])) +(local state (client.new-state #(do {:repl nil}))) +(local buf-suffix ".scm") +(local comment-prefix "; ") +(local form-node? ts.node-surrounded-by-form-pair-chars?) -(defn- with-repl-or-warn [f opts] +(fn with-repl-or-warn [f opts] (let [repl (state :repl)] (if repl (f repl) (log.append [(.. comment-prefix "No REPL running")])))) ;;;;-------- from client/sql/stdio.fnl ---------------------- -(defn- format-message [msg] +(fn format-message [msg] (str.split (or msg.out msg.err) "\n")) -(defn- remove-blank-lines [msg] +(fn remove-blank-lines [msg] (->> (format-message msg) (a.filter #(not (= "" $1))))) -(defn- display-result [msg] +(fn display-result [msg] (log.append (remove-blank-lines msg))) -(defn ->list [s] +(fn ->list [s] (if (a.first s) s [s])) -(defn eval-str [opts] +(fn eval-str [opts] (with-repl-or-warn (fn [repl] (repl.send @@ -89,30 +86,31 @@ {:batch? false})))) ;;;;-------- End from client/sql/stdio.fnl ------------------ -(defn eval-file [opts] +(fn eval-file [opts] (eval-str (a.assoc opts :code (.. "(load \"" opts.file-path "\")")))) -(defn interrupt [] +(fn interrupt [] (with-repl-or-warn (fn [repl] (log.append [(.. comment-prefix " Sending interrupt signal.")] {:break? true}) (repl.send-signal vim.loop.constants.SIGINT)))) -(defn- display-repl-status [status] +(fn display-repl-status [status] (log.append [(.. comment-prefix (cfg [:command]) " (" (or status "no status") ")")] {:break? true})) -(defn stop [] +(fn stop [] (let [repl (state :repl)] (when repl (repl.destroy) (display-repl-status :stopped) (a.assoc (state) :repl nil)))) -(defn start [] +(fn start [] + (log.append [(.. comment-prefix "Starting snd-s7 client...")]) (if (state :repl) (log.append [(.. comment-prefix "Can't start, REPL is already running.") (.. comment-prefix "Stop the REPL with " @@ -145,13 +143,14 @@ (fn [msg] (log.append (format-msg msg)))})))) -(defn on-load [] - (start)) +(fn on-load [] + (when (config.get-in [:client_on_load]) + (start))) -(defn on-exit [] +(fn on-exit [] (stop)) -(defn on-filetype [] +(fn on-filetype [] (mapping.buf :SndStart (cfg [:mapping :start]) start @@ -167,4 +166,15 @@ interrupt {:desc "Interrupt the REPL"})) -*module* +{: buf-suffix + : comment-prefix + : form-node? + : ->list + : eval-str + : eval-file + : interrupt + : stop + : start + : on-load + : on-exit + : on-filetype} diff --git a/lua/conjure/client/snd-s7/stdio.lua b/lua/conjure/client/snd-s7/stdio.lua index be372c0e..3c37e40e 100644 --- a/lua/conjure/client/snd-s7/stdio.lua +++ b/lua/conjure/client/snd-s7/stdio.lua @@ -1,52 +1,29 @@ -- [nfnl] Compiled from fnl/conjure/client/snd-s7/stdio.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.client.snd-s7.stdio" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, client, config, log, mapping, nvim, stdio, str, ts, _ = autoload("conjure.aniseed.core"), autoload("conjure.client"), autoload("conjure.config"), autoload("conjure.log"), autoload("conjure.mapping"), autoload("conjure.aniseed.nvim"), autoload("conjure.remote.stdio-rt"), autoload("conjure.aniseed.string"), autoload("conjure.tree-sitter"), nil -_2amodule_locals_2a["a"] = a -_2amodule_locals_2a["client"] = client -_2amodule_locals_2a["config"] = config -_2amodule_locals_2a["log"] = log -_2amodule_locals_2a["mapping"] = mapping -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["stdio"] = stdio -_2amodule_locals_2a["str"] = str -_2amodule_locals_2a["ts"] = ts -_2amodule_locals_2a["_"] = _ -do local _ = {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local nvim = autoload("conjure.aniseed.nvim") +local str = autoload("conjure.aniseed.string") +local client = autoload("conjure.client") +local log = autoload("conjure.log") +local stdio = autoload("conjure.remote.stdio-rt") +local config = autoload("conjure.config") +local mapping = autoload("conjure.mapping") +local ts = autoload("conjure.tree-sitter") config.merge({client = {["snd-s7"] = {stdio = {command = "snd", prompt_pattern = "> "}}}}) if config["get-in"]({"mapping", "enable_defaults"}) then config.merge({client = {["snd-s7"] = {stdio = {mapping = {start = "cs", stop = "cS", interrupt = "ei"}}}}}) else end local cfg = config["get-in-fn"]({"client", "snd-s7", "stdio"}) -do end (_2amodule_locals_2a)["cfg"] = cfg -do local _ = {nil, nil} end local state -local function _2_() +local function _3_() return {repl = nil} end -state = ((_2amodule_2a).state or client["new-state"](_2_)) -do end (_2amodule_locals_2a)["state"] = state -do local _ = {nil, nil} end +state = client["new-state"](_3_) local buf_suffix = ".scm" -_2amodule_2a["buf-suffix"] = buf_suffix -do local _ = {nil, nil} end local comment_prefix = "; " -_2amodule_2a["comment-prefix"] = comment_prefix -do local _ = {nil, nil} end local form_node_3f = ts["node-surrounded-by-form-pair-chars?"] -_2amodule_2a["form-node?"] = form_node_3f -do local _ = {nil, nil} end local function with_repl_or_warn(f, opts) local repl = state("repl") if repl then @@ -55,26 +32,18 @@ local function with_repl_or_warn(f, opts) return log.append({(comment_prefix .. "No REPL running")}) end end -_2amodule_locals_2a["with-repl-or-warn"] = with_repl_or_warn -do local _ = {with_repl_or_warn, nil} end local function format_message(msg) return str.split((msg.out or msg.err), "\n") end -_2amodule_locals_2a["format-message"] = format_message -do local _ = {format_message, nil} end local function remove_blank_lines(msg) - local function _4_(_241) + local function _5_(_241) return not ("" == _241) end - return a.filter(_4_, format_message(msg)) + return a.filter(_5_, format_message(msg)) end -_2amodule_locals_2a["remove-blank-lines"] = remove_blank_lines -do local _ = {remove_blank_lines, nil} end local function display_result(msg) return log.append(remove_blank_lines(msg)) end -_2amodule_locals_2a["display-result"] = display_result -do local _ = {display_result, nil} end local function __3elist(s) if a.first(s) then return s @@ -82,11 +51,9 @@ local function __3elist(s) return {s} end end -_2amodule_2a["->list"] = __3elist -do local _ = {__3elist, nil} end local function eval_str(opts) - local function _6_(repl) - local function _7_(msgs) + local function _7_(repl) + local function _8_(msgs) local msgs0 = __3elist(msgs) if opts["on-result"] then opts["on-result"](str.join("\n", remove_blank_lines(a.last(msgs0)))) @@ -94,31 +61,23 @@ local function eval_str(opts) end return a["run!"](display_result, msgs0) end - return repl.send((opts.code .. "\n"), _7_, {["batch?"] = false}) + return repl.send((opts.code .. "\n"), _8_, {["batch?"] = false}) end - return with_repl_or_warn(_6_) + return with_repl_or_warn(_7_) end -_2amodule_2a["eval-str"] = eval_str -do local _ = {eval_str, nil} end local function eval_file(opts) return eval_str(a.assoc(opts, "code", ("(load \"" .. opts["file-path"] .. "\")"))) end -_2amodule_2a["eval-file"] = eval_file -do local _ = {eval_file, nil} end local function interrupt() - local function _9_(repl) + local function _10_(repl) log.append({(comment_prefix .. " Sending interrupt signal.")}, {["break?"] = true}) return repl["send-signal"](vim.loop.constants.SIGINT) end - return with_repl_or_warn(_9_) + return with_repl_or_warn(_10_) end -_2amodule_2a["interrupt"] = interrupt -do local _ = {interrupt, nil} end local function display_repl_status(status) return log.append({(comment_prefix .. cfg({"command"}) .. " (" .. (status or "no status") .. ")")}, {["break?"] = true}) end -_2amodule_locals_2a["display-repl-status"] = display_repl_status -do local _ = {display_repl_status, nil} end local function stop() local repl = state("repl") if repl then @@ -129,19 +88,18 @@ local function stop() return nil end end -_2amodule_2a["stop"] = stop -do local _ = {stop, nil} end local function start() + log.append({(comment_prefix .. "Starting snd-s7 client...")}) if state("repl") then return log.append({(comment_prefix .. "Can't start, REPL is already running."), (comment_prefix .. "Stop the REPL with " .. config["get-in"]({"mapping", "prefix"}) .. cfg({"mapping", "stop"}))}, {["break?"] = true}) else - local function _11_() + local function _12_() return display_repl_status("started") end - local function _12_(err) + local function _13_(err) return display_repl_status(err) end - local function _13_(code, signal) + local function _14_(code, signal) if (("number" == type(code)) and (code > 0)) then log.append({(comment_prefix .. "process exited with code " .. code)}) else @@ -152,29 +110,25 @@ local function start() end return stop() end - local function _16_(msg) + local function _17_(msg) return log.append(__fnl_global__format_2dmsg(msg)) end - return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt_pattern"}), cmd = cfg({"command"}), ["on-success"] = _11_, ["on-error"] = _12_, ["on-exit"] = _13_, ["on-stray-output"] = _16_})) + return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt_pattern"}), cmd = cfg({"command"}), ["on-success"] = _12_, ["on-error"] = _13_, ["on-exit"] = _14_, ["on-stray-output"] = _17_})) end end -_2amodule_2a["start"] = start -do local _ = {start, nil} end local function on_load() - return start() + if config["get-in"]({"client_on_load"}) then + return start() + else + return nil + end end -_2amodule_2a["on-load"] = on_load -do local _ = {on_load, nil} end local function on_exit() return stop() end -_2amodule_2a["on-exit"] = on_exit -do local _ = {on_exit, nil} end local function on_filetype() mapping.buf("SndStart", cfg({"mapping", "start"}), start, {desc = "Start the REPL"}) mapping.buf("SndStop", cfg({"mapping", "stop"}), stop, {desc = "Stop the REPL"}) return mapping.buf("SdnInterrupt", cfg({"mapping", "interrupt"}), interrupt, {desc = "Interrupt the REPL"}) end -_2amodule_2a["on-filetype"] = on_filetype -do local _ = {on_filetype, nil} end -return _2amodule_2a +return {["buf-suffix"] = buf_suffix, ["comment-prefix"] = comment_prefix, ["form-node?"] = form_node_3f, ["->list"] = __3elist, ["eval-str"] = eval_str, ["eval-file"] = eval_file, interrupt = interrupt, stop = stop, start = start, ["on-load"] = on_load, ["on-exit"] = on_exit, ["on-filetype"] = on_filetype} From a53a37d05c49f0a5ada88c2894eb5d6380cd626d Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Tue, 27 Aug 2024 13:00:28 -1000 Subject: [PATCH 02/13] Remove unused import-macros --- fnl/conjure/client/snd-s7/stdio.fnl | 2 -- 1 file changed, 2 deletions(-) diff --git a/fnl/conjure/client/snd-s7/stdio.fnl b/fnl/conjure/client/snd-s7/stdio.fnl index 052d9261..d6fab2bb 100644 --- a/fnl/conjure/client/snd-s7/stdio.fnl +++ b/fnl/conjure/client/snd-s7/stdio.fnl @@ -9,8 +9,6 @@ (local mapping (autoload :conjure.mapping)) (local ts (autoload :conjure.tree-sitter)) -(import-macros {: augroup : autocmd} :conjure.macros) - ;;------------------------------------------------------------ ;; A client for snd/s7 (sound editor with s7 scheme scripting) ;; From e5d52ac662b2616ce4b54a14b41c30901308b0c7 Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Tue, 27 Aug 2024 13:07:41 -1000 Subject: [PATCH 03/13] Convert Python client --- fnl/conjure/client/python/stdio.fnl | 111 ++++++++++--------- lua/conjure/client/python/stdio.lua | 160 ++++++++-------------------- 2 files changed, 107 insertions(+), 164 deletions(-) diff --git a/fnl/conjure/client/python/stdio.fnl b/fnl/conjure/client/python/stdio.fnl index a594ceea..8ec54c45 100644 --- a/fnl/conjure/client/python/stdio.fnl +++ b/fnl/conjure/client/python/stdio.fnl @@ -1,19 +1,15 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) - -(module conjure.client.python.stdio - {autoload {a conjure.aniseed.core - extract conjure.extract - str conjure.aniseed.string - nvim conjure.aniseed.nvim - stdio conjure.remote.stdio - config conjure.config - text conjure.text - mapping conjure.mapping - client conjure.client - log conjure.log - ts conjure.tree-sitter - b64 conjure.remote.transport.base64} - require-macros [conjure.macros]}) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local extract (autoload :conjure.extract)) +(local str (autoload :conjure.aniseed.string)) +(local stdio (autoload :conjure.remote.stdio)) +(local config (autoload :conjure.config)) +(local text (autoload :conjure.text)) +(local mapping (autoload :conjure.mapping)) +(local client (autoload :conjure.client)) +(local log (autoload :conjure.log)) +(local ts (autoload :conjure.tree-sitter)) +(local b64 (autoload :conjure.remote.transport.base64)) (config.merge {:client @@ -32,17 +28,15 @@ :stop "cS" :interrupt "ei"}}}}})) -(def- cfg (config.get-in-fn [:client :python :stdio])) - -(defonce- state (client.new-state #(do {:repl nil}))) - -(def buf-suffix ".py") -(def comment-prefix "# ") +(local cfg (config.get-in-fn [:client :python :stdio])) +(local state (client.new-state #(do {:repl nil}))) +(local buf-suffix ".py") +(local comment-prefix "# ") ; These types of nodes are roughly equivalent to Lisp forms. ; This should make it more intuitive to use ee to evaluate the ; "current form" and not be surprised that it wasn't what you thought. -(defn form-node? +(fn form-node? [node] (or (= "expression_statement" (node:type)) (= "import_statement" (node:type)) @@ -52,7 +46,7 @@ (= "for_statement" (node:type)) (= "call" (node:type)))) -(defn- with-repl-or-warn [f opts] +(fn with-repl-or-warn [f opts] (let [repl (state :repl)] (if repl (f repl) @@ -66,13 +60,13 @@ ; Returns whether a given expression node is an assignment expression ; An assignment expression seems to be a weird case where it does not actually ; evaluate to anything so it seems more like a statement -(defn is-assignment? +(fn is-assignment? [node] (and (= (node:child_count) 1) (let [child (node:child 0)] (= (child:type) "assignment")))) -(defn is-expression? +(fn is-expression? [node] (and (= "expression_statement" (node:type)) (not (is-assignment? node)))) @@ -104,7 +98,7 @@ ; for this. Another option that I have seen used in some other similar projects is sending the statement ; as a "bracketed paste" (https://cirw.in/blog/bracketed-paste) so the REPL treats the input as if it were ; "pasted", but I couldn't get this working. -(defn str-is-python-expr? +(fn str-is-python-expr? [s] (let [parser (vim.treesitter.get_string_parser s "python") result (parser:parse) @@ -113,11 +107,11 @@ (and (= 1 (root:child_count)) (is-expression? (root:child 0))))) -(defn- get-exec-str +(fn get-exec-str [s] (.. "import base64\nexec(base64.b64decode('" (b64.encode s) "'))\n")) -(defn- prep-code [s] +(fn prep-code [s] (let [python-expr (str-is-python-expr? s)] (if python-expr (.. s "\n") @@ -131,31 +125,31 @@ ; print("... <-- check out those dots") ; the output will be flagged as one of these special "dots" lines. This could probably ; be smarter, but will work for most normal cases for now. -(defn- is-dots? [s] +(fn is-dots? [s] (= (string.sub s 1 3) "...")) -(defn format-msg [msg] +(fn format-msg [msg] (->> (text.split-lines msg) (a.filter #(~= "" $1)) (a.filter #(not (is-dots? $1))))) -(defn- get-console-output-msgs [msgs] +(fn get-console-output-msgs [msgs] (->> (a.butlast msgs) (a.map #(.. comment-prefix "(out) " $1)))) -(defn- get-expression-result [msgs] +(fn get-expression-result [msgs] (let [result (a.last msgs)] (if (or (a.nil? result) (is-dots? result)) nil result))) -(defn unbatch [msgs] +(fn unbatch [msgs] (->> msgs (a.map #(or (a.get $1 :out) (a.get $1 :err))) (str.join ""))) -(defn- log-repl-output [msgs] +(fn log-repl-output [msgs] (let [msgs (-> msgs unbatch format-msg) console-output-msgs (get-console-output-msgs msgs) cmd-result (get-expression-result msgs)] @@ -164,7 +158,7 @@ (when cmd-result (log.append [cmd-result])))) -(defn eval-str [opts] +(fn eval-str [opts] (with-repl-or-warn (fn [repl] (repl.send @@ -177,31 +171,31 @@ (opts.on-result cmd-result)))) {:batch? true})))) -(defn eval-file [opts] +(fn eval-file [opts] (eval-str (a.assoc opts :code (a.slurp opts.file-path)))) -(defn get-help [code] +(fn get-help [code] (str.join "" ["help(" (str.trim code) ")"])) -(defn doc-str [opts] +(fn doc-str [opts] (when (str-is-python-expr? opts.code) (eval-str (a.assoc opts :code (get-help opts.code))))) -(defn- display-repl-status [status] +(fn display-repl-status [status] (let [repl (state :repl)] (when repl (log.append [(.. comment-prefix (a.pr-str (a.get-in repl [:opts :cmd])) " (" status ")")] {:break? true})))) -(defn stop [] +(fn stop [] (let [repl (state :repl)] (when repl (repl.destroy) (display-repl-status :stopped) (a.assoc (state) :repl nil)))) -(def initialise-repl-code +(local initialise-repl-code ;; By default, there is no way for us to tell the difference between ;; normal stdout log messages and the result of the expression we evaluated. ;; This is because if an expression results in the literal value None, the python @@ -219,7 +213,8 @@ "sys.displayhook = conjure_format_output\n" "__name__ = '__repl__'"])) -(defn start [] +(fn start [] + (log.append [(.. comment-prefix "Starting Python client...")]) (if (state :repl) (log.append [(.. comment-prefix "Can't start, REPL is already running.") (.. comment-prefix "Stop the REPL with " @@ -265,22 +260,22 @@ (fn [msg] (log.dbg (-> [msg] unbatch format-msg) {:join-first? true}))}))))) -(defn on-load [] +(fn on-load [] (if (config.get-in [:client_on_load]) - (do + (do ; FIXME: Can we remove the do? (start)) (log.append ["Not starting repl"]))) -(defn on-exit [] +(fn on-exit [] (stop)) -(defn interrupt [] +(fn interrupt [] (with-repl-or-warn (fn [repl] (log.append [(.. comment-prefix " Sending interrupt signal.")] {:break? true}) (repl.send-signal vim.loop.constants.SIGINT)))) -(defn on-filetype [] +(fn on-filetype [] (mapping.buf :PythonStart (cfg [:mapping :start]) start @@ -296,4 +291,22 @@ interrupt {:desc "Interrupt the current evaluation"})) -*module* +{: buf-suffix + : comment-prefix + : form-node? + : is-assignment? + : is-expression? + : str-is-python-expr? + : format-msg + : unbatch + : eval-str + : eval-file + : get-help + : doc-str + : stop + : initialise-repl-code + : start + : on-load + : on-exit + : interrupt + : on-filetype } diff --git a/lua/conjure/client/python/stdio.lua b/lua/conjure/client/python/stdio.lua index de1830fb..02890b84 100644 --- a/lua/conjure/client/python/stdio.lua +++ b/lua/conjure/client/python/stdio.lua @@ -1,57 +1,33 @@ -- [nfnl] Compiled from fnl/conjure/client/python/stdio.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.client.python.stdio" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, b64, client, config, extract, log, mapping, nvim, stdio, str, text, ts, _ = autoload("conjure.aniseed.core"), autoload("conjure.remote.transport.base64"), autoload("conjure.client"), autoload("conjure.config"), autoload("conjure.extract"), autoload("conjure.log"), autoload("conjure.mapping"), autoload("conjure.aniseed.nvim"), autoload("conjure.remote.stdio"), autoload("conjure.aniseed.string"), autoload("conjure.text"), autoload("conjure.tree-sitter"), nil -_2amodule_locals_2a["a"] = a -_2amodule_locals_2a["b64"] = b64 -_2amodule_locals_2a["client"] = client -_2amodule_locals_2a["config"] = config -_2amodule_locals_2a["extract"] = extract -_2amodule_locals_2a["log"] = log -_2amodule_locals_2a["mapping"] = mapping -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["stdio"] = stdio -_2amodule_locals_2a["str"] = str -_2amodule_locals_2a["text"] = text -_2amodule_locals_2a["ts"] = ts -_2amodule_locals_2a["_"] = _ -do local _ = {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local extract = autoload("conjure.extract") +local str = autoload("conjure.aniseed.string") +local stdio = autoload("conjure.remote.stdio") +local config = autoload("conjure.config") +local text = autoload("conjure.text") +local mapping = autoload("conjure.mapping") +local client = autoload("conjure.client") +local log = autoload("conjure.log") +local ts = autoload("conjure.tree-sitter") +local b64 = autoload("conjure.remote.transport.base64") config.merge({client = {python = {stdio = {command = "python3 -iq", ["prompt-pattern"] = ">>> ", ["delay-stderr-ms"] = 10}}}}) if config["get-in"]({"mapping", "enable_defaults"}) then config.merge({client = {python = {stdio = {mapping = {start = "cs", stop = "cS", interrupt = "ei"}}}}}) else end local cfg = config["get-in-fn"]({"client", "python", "stdio"}) -do end (_2amodule_locals_2a)["cfg"] = cfg -do local _ = {nil, nil} end local state -local function _2_() +local function _3_() return {repl = nil} end -state = ((_2amodule_2a).state or client["new-state"](_2_)) -do end (_2amodule_locals_2a)["state"] = state -do local _ = {nil, nil} end +state = client["new-state"](_3_) local buf_suffix = ".py" -_2amodule_2a["buf-suffix"] = buf_suffix -do local _ = {nil, nil} end local comment_prefix = "# " -_2amodule_2a["comment-prefix"] = comment_prefix -do local _ = {nil, nil} end local function form_node_3f(node) return (("expression_statement" == node:type()) or ("import_statement" == node:type()) or ("import_from_statement" == node:type()) or ("with_statement" == node:type()) or ("function_definition" == node:type()) or ("for_statement" == node:type()) or ("call" == node:type())) end -_2amodule_2a["form-node?"] = form_node_3f -do local _ = {form_node_3f, nil} end local function with_repl_or_warn(f, opts) local repl = state("repl") if repl then @@ -60,22 +36,17 @@ local function with_repl_or_warn(f, opts) return log.append({(comment_prefix .. "No REPL running"), (comment_prefix .. "Start REPL with " .. config["get-in"]({"mapping", "prefix"}) .. cfg({"mapping", "start"}))}) end end -_2amodule_locals_2a["with-repl-or-warn"] = with_repl_or_warn -do local _ = {with_repl_or_warn, nil} end local function is_assignment_3f(node) - local function _4_() + local and_5_ = (node:child_count() == 1) + if and_5_ then local child = node:child(0) - return (child:type() == "assignment") + and_5_ = (child:type() == "assignment") end - return ((node:child_count() == 1) and _4_()) + return and_5_ end -_2amodule_2a["is-assignment?"] = is_assignment_3f -do local _ = {is_assignment_3f, nil} end local function is_expression_3f(node) return (("expression_statement" == node:type()) and not is_assignment_3f(node)) end -_2amodule_2a["is-expression?"] = is_expression_3f -do local _ = {is_expression_3f, nil} end local function str_is_python_expr_3f(s) local parser = vim.treesitter.get_string_parser(s, "python") local result = parser:parse() @@ -83,13 +54,9 @@ local function str_is_python_expr_3f(s) local root = tree:root() return ((1 == root:child_count()) and is_expression_3f(root:child(0))) end -_2amodule_2a["str-is-python-expr?"] = str_is_python_expr_3f -do local _ = {str_is_python_expr_3f, nil} end local function get_exec_str(s) return ("import base64\nexec(base64.b64decode('" .. b64.encode(s) .. "'))\n") end -_2amodule_locals_2a["get-exec-str"] = get_exec_str -do local _ = {get_exec_str, nil} end local function prep_code(s) local python_expr = str_is_python_expr_3f(s) if python_expr then @@ -98,32 +65,24 @@ local function prep_code(s) return get_exec_str(s) end end -_2amodule_locals_2a["prep-code"] = prep_code -do local _ = {prep_code, nil} end local function is_dots_3f(s) return (string.sub(s, 1, 3) == "...") end -_2amodule_locals_2a["is-dots?"] = is_dots_3f -do local _ = {is_dots_3f, nil} end local function format_msg(msg) - local function _6_(_241) + local function _8_(_241) return not is_dots_3f(_241) end - local function _7_(_241) + local function _9_(_241) return ("" ~= _241) end - return a.filter(_6_, a.filter(_7_, text["split-lines"](msg))) + return a.filter(_8_, a.filter(_9_, text["split-lines"](msg))) end -_2amodule_2a["format-msg"] = format_msg -do local _ = {format_msg, nil} end local function get_console_output_msgs(msgs) - local function _8_(_241) + local function _10_(_241) return (comment_prefix .. "(out) " .. _241) end - return a.map(_8_, a.butlast(msgs)) + return a.map(_10_, a.butlast(msgs)) end -_2amodule_locals_2a["get-console-output-msgs"] = get_console_output_msgs -do local _ = {get_console_output_msgs, nil} end local function get_expression_result(msgs) local result = a.last(msgs) if (a["nil?"](result) or is_dots_3f(result)) then @@ -132,16 +91,12 @@ local function get_expression_result(msgs) return result end end -_2amodule_locals_2a["get-expression-result"] = get_expression_result -do local _ = {get_expression_result, nil} end local function unbatch(msgs) - local function _10_(_241) + local function _12_(_241) return (a.get(_241, "out") or a.get(_241, "err")) end - return str.join("", a.map(_10_, msgs)) + return str.join("", a.map(_12_, msgs)) end -_2amodule_2a["unbatch"] = unbatch -do local _ = {unbatch, nil} end local function log_repl_output(msgs) local msgs0 = format_msg(unbatch(msgs)) local console_output_msgs = get_console_output_msgs(msgs0) @@ -156,11 +111,9 @@ local function log_repl_output(msgs) return nil end end -_2amodule_locals_2a["log-repl-output"] = log_repl_output -do local _ = {log_repl_output, nil} end local function eval_str(opts) - local function _13_(repl) - local function _14_(msgs) + local function _15_(repl) + local function _16_(msgs) log_repl_output(msgs) if opts["on-result"] then local msgs0 = format_msg(unbatch(msgs)) @@ -170,22 +123,16 @@ local function eval_str(opts) return nil end end - return repl.send(prep_code(opts.code), _14_, {["batch?"] = true}) + return repl.send(prep_code(opts.code), _16_, {["batch?"] = true}) end - return with_repl_or_warn(_13_) + return with_repl_or_warn(_15_) end -_2amodule_2a["eval-str"] = eval_str -do local _ = {eval_str, nil} end local function eval_file(opts) return eval_str(a.assoc(opts, "code", a.slurp(opts["file-path"]))) end -_2amodule_2a["eval-file"] = eval_file -do local _ = {eval_file, nil} end local function get_help(code) return str.join("", {"help(", str.trim(code), ")"}) end -_2amodule_2a["get-help"] = get_help -do local _ = {get_help, nil} end local function doc_str(opts) if str_is_python_expr_3f(opts.code) then return eval_str(a.assoc(opts, "code", get_help(opts.code))) @@ -193,8 +140,6 @@ local function doc_str(opts) return nil end end -_2amodule_2a["doc-str"] = doc_str -do local _ = {doc_str, nil} end local function display_repl_status(status) local repl = state("repl") if repl then @@ -203,8 +148,6 @@ local function display_repl_status(status) return nil end end -_2amodule_locals_2a["display-repl-status"] = display_repl_status -do local _ = {display_repl_status, nil} end local function stop() local repl = state("repl") if repl then @@ -215,38 +158,35 @@ local function stop() return nil end end -_2amodule_2a["stop"] = stop -do local _ = {stop, nil} end local initialise_repl_code = str.join("\n", {"import sys", "def conjure_format_output(val):", " print(repr(val))", "sys.displayhook = conjure_format_output\n", "__name__ = '__repl__'"}) -do end (_2amodule_2a)["initialise-repl-code"] = initialise_repl_code -do local _ = {nil, nil} end local function start() + log.append({(comment_prefix .. "Starting Python client...")}) if state("repl") then return log.append({(comment_prefix .. "Can't start, REPL is already running."), (comment_prefix .. "Stop the REPL with " .. config["get-in"]({"mapping", "prefix"}) .. cfg({"mapping", "stop"}))}, {["break?"] = true}) else - local function _19_() + local function _21_() if vim.treesitter.language.require_language then return vim.treesitter.language.require_language("python") else return vim.treesitter.require_language("python") end end - if not pcall(_19_) then + if not pcall(_21_) then return log.append({(comment_prefix .. "(error) The python client requires a python treesitter parser in order to function."), (comment_prefix .. "(error) See https://github.com/nvim-treesitter/nvim-treesitter"), (comment_prefix .. "(error) for installation instructions.")}) else - local function _21_() - local function _22_(repl) - local function _23_(msgs) + local function _23_() + local function _24_(repl) + local function _25_(msgs) return nil end - return repl.send(prep_code(initialise_repl_code), _23_, nil) + return repl.send(prep_code(initialise_repl_code), _25_, nil) end - return display_repl_status("started", with_repl_or_warn(_22_)) + return display_repl_status("started", with_repl_or_warn(_24_)) end - local function _24_(err) + local function _26_(err) return display_repl_status(err) end - local function _25_(code, signal) + local function _27_(code, signal) if (("number" == type(code)) and (code > 0)) then log.append({(comment_prefix .. "process exited with code " .. code)}) else @@ -257,15 +197,13 @@ local function start() end return stop() end - local function _28_(msg) + local function _30_(msg) return log.dbg(format_msg(unbatch({msg})), {["join-first?"] = true}) end - return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt-pattern"}), cmd = cfg({"command"}), ["delay-stderr-ms"] = cfg({"delay-stderr-ms"}), ["on-success"] = _21_, ["on-error"] = _24_, ["on-exit"] = _25_, ["on-stray-output"] = _28_})) + return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt-pattern"}), cmd = cfg({"command"}), ["delay-stderr-ms"] = cfg({"delay-stderr-ms"}), ["on-success"] = _23_, ["on-error"] = _26_, ["on-exit"] = _27_, ["on-stray-output"] = _30_})) end end end -_2amodule_2a["start"] = start -do local _ = {start, nil} end local function on_load() if config["get-in"]({"client_on_load"}) then return start() @@ -273,27 +211,19 @@ local function on_load() return log.append({"Not starting repl"}) end end -_2amodule_2a["on-load"] = on_load -do local _ = {on_load, nil} end local function on_exit() return stop() end -_2amodule_2a["on-exit"] = on_exit -do local _ = {on_exit, nil} end local function interrupt() - local function _32_(repl) + local function _34_(repl) log.append({(comment_prefix .. " Sending interrupt signal.")}, {["break?"] = true}) return repl["send-signal"](vim.loop.constants.SIGINT) end - return with_repl_or_warn(_32_) + return with_repl_or_warn(_34_) end -_2amodule_2a["interrupt"] = interrupt -do local _ = {interrupt, nil} end local function on_filetype() mapping.buf("PythonStart", cfg({"mapping", "start"}), start, {desc = "Start the Python REPL"}) mapping.buf("PythonStop", cfg({"mapping", "stop"}), stop, {desc = "Stop the Python REPL"}) return mapping.buf("PythonInterrupt", cfg({"mapping", "interrupt"}), interrupt, {desc = "Interrupt the current evaluation"}) end -_2amodule_2a["on-filetype"] = on_filetype -do local _ = {on_filetype, nil} end -return _2amodule_2a +return {["buf-suffix"] = buf_suffix, ["comment-prefix"] = comment_prefix, ["form-node?"] = form_node_3f, ["is-assignment?"] = is_assignment_3f, ["is-expression?"] = is_expression_3f, ["str-is-python-expr?"] = str_is_python_expr_3f, ["format-msg"] = format_msg, unbatch = unbatch, ["eval-str"] = eval_str, ["eval-file"] = eval_file, ["get-help"] = get_help, ["doc-str"] = doc_str, stop = stop, ["initialise-repl-code"] = initialise_repl_code, start = start, ["on-load"] = on_load, ["on-exit"] = on_exit, interrupt = interrupt, ["on-filetype"] = on_filetype} From 1ffe997d1168fd35f43a73ea3dcbe270ec75870d Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Tue, 27 Aug 2024 14:27:39 -1000 Subject: [PATCH 04/13] Make Python client closer to other stdio clients --- fnl/conjure/client/python/stdio.fnl | 21 ++++++------- lua/conjure/client/python/stdio.lua | 47 +++++++++++++---------------- 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/fnl/conjure/client/python/stdio.fnl b/fnl/conjure/client/python/stdio.fnl index 8ec54c45..48c4e736 100644 --- a/fnl/conjure/client/python/stdio.fnl +++ b/fnl/conjure/client/python/stdio.fnl @@ -182,11 +182,11 @@ (eval-str (a.assoc opts :code (get-help opts.code))))) (fn display-repl-status [status] - (let [repl (state :repl)] - (when repl - (log.append - [(.. comment-prefix (a.pr-str (a.get-in repl [:opts :cmd])) " (" status ")")] - {:break? true})))) + ( log.append + [(.. comment-prefix + (cfg [:command]) + " (" (or status "no status") ")")] + {:break? true})) (fn stop [] (let [repl (state :repl)] @@ -260,12 +260,6 @@ (fn [msg] (log.dbg (-> [msg] unbatch format-msg) {:join-first? true}))}))))) -(fn on-load [] - (if (config.get-in [:client_on_load]) - (do ; FIXME: Can we remove the do? - (start)) - (log.append ["Not starting repl"]))) - (fn on-exit [] (stop)) @@ -275,6 +269,11 @@ (log.append [(.. comment-prefix " Sending interrupt signal.")] {:break? true}) (repl.send-signal vim.loop.constants.SIGINT)))) +(fn on-load [] + ;; Start up REPL only if g.conjure#client_on_load is v:true. + (when (config.get-in [:client_on_load]) + (start))) + (fn on-filetype [] (mapping.buf :PythonStart (cfg [:mapping :start]) diff --git a/lua/conjure/client/python/stdio.lua b/lua/conjure/client/python/stdio.lua index 02890b84..3da6ad12 100644 --- a/lua/conjure/client/python/stdio.lua +++ b/lua/conjure/client/python/stdio.lua @@ -141,12 +141,7 @@ local function doc_str(opts) end end local function display_repl_status(status) - local repl = state("repl") - if repl then - return log.append({(comment_prefix .. a["pr-str"](a["get-in"](repl, {"opts", "cmd"})) .. " (" .. status .. ")")}, {["break?"] = true}) - else - return nil - end + return log.append({(comment_prefix .. cfg({"command"}) .. " (" .. (status or "no status") .. ")")}, {["break?"] = true}) end local function stop() local repl = state("repl") @@ -164,29 +159,29 @@ local function start() if state("repl") then return log.append({(comment_prefix .. "Can't start, REPL is already running."), (comment_prefix .. "Stop the REPL with " .. config["get-in"]({"mapping", "prefix"}) .. cfg({"mapping", "stop"}))}, {["break?"] = true}) else - local function _21_() + local function _20_() if vim.treesitter.language.require_language then return vim.treesitter.language.require_language("python") else return vim.treesitter.require_language("python") end end - if not pcall(_21_) then + if not pcall(_20_) then return log.append({(comment_prefix .. "(error) The python client requires a python treesitter parser in order to function."), (comment_prefix .. "(error) See https://github.com/nvim-treesitter/nvim-treesitter"), (comment_prefix .. "(error) for installation instructions.")}) else - local function _23_() - local function _24_(repl) - local function _25_(msgs) + local function _22_() + local function _23_(repl) + local function _24_(msgs) return nil end - return repl.send(prep_code(initialise_repl_code), _25_, nil) + return repl.send(prep_code(initialise_repl_code), _24_, nil) end - return display_repl_status("started", with_repl_or_warn(_24_)) + return display_repl_status("started", with_repl_or_warn(_23_)) end - local function _26_(err) + local function _25_(err) return display_repl_status(err) end - local function _27_(code, signal) + local function _26_(code, signal) if (("number" == type(code)) and (code > 0)) then log.append({(comment_prefix .. "process exited with code " .. code)}) else @@ -197,29 +192,29 @@ local function start() end return stop() end - local function _30_(msg) + local function _29_(msg) return log.dbg(format_msg(unbatch({msg})), {["join-first?"] = true}) end - return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt-pattern"}), cmd = cfg({"command"}), ["delay-stderr-ms"] = cfg({"delay-stderr-ms"}), ["on-success"] = _23_, ["on-error"] = _26_, ["on-exit"] = _27_, ["on-stray-output"] = _30_})) + return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt-pattern"}), cmd = cfg({"command"}), ["delay-stderr-ms"] = cfg({"delay-stderr-ms"}), ["on-success"] = _22_, ["on-error"] = _25_, ["on-exit"] = _26_, ["on-stray-output"] = _29_})) end end end -local function on_load() - if config["get-in"]({"client_on_load"}) then - return start() - else - return log.append({"Not starting repl"}) - end -end local function on_exit() return stop() end local function interrupt() - local function _34_(repl) + local function _32_(repl) log.append({(comment_prefix .. " Sending interrupt signal.")}, {["break?"] = true}) return repl["send-signal"](vim.loop.constants.SIGINT) end - return with_repl_or_warn(_34_) + return with_repl_or_warn(_32_) +end +local function on_load() + if config["get-in"]({"client_on_load"}) then + return start() + else + return nil + end end local function on_filetype() mapping.buf("PythonStart", cfg({"mapping", "start"}), start, {desc = "Start the Python REPL"}) From a54da440a046ad5c02552d8dc4c15e2c509b549d Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Tue, 27 Aug 2024 14:28:19 -1000 Subject: [PATCH 05/13] Convert Scheme client --- fnl/conjure/client/scheme/stdio.fnl | 74 ++++++++++--------- lua/conjure/client/scheme/stdio.lua | 107 ++++++++-------------------- 2 files changed, 70 insertions(+), 111 deletions(-) diff --git a/fnl/conjure/client/scheme/stdio.fnl b/fnl/conjure/client/scheme/stdio.fnl index b069a0b4..48d30b8f 100644 --- a/fnl/conjure/client/scheme/stdio.fnl +++ b/fnl/conjure/client/scheme/stdio.fnl @@ -1,16 +1,13 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) - -(module conjure.client.scheme.stdio - {autoload {a conjure.aniseed.core - str conjure.aniseed.string - nvim conjure.aniseed.nvim - stdio conjure.remote.stdio - config conjure.config - mapping conjure.mapping - client conjure.client - log conjure.log - ts conjure.tree-sitter} - require-macros [conjure.macros]}) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local str (autoload :conjure.aniseed.string)) +(local stdio (autoload :conjure.remote.stdio)) +(local config (autoload :conjure.config)) +(local text (autoload :conjure.text)) +(local mapping (autoload :conjure.mapping)) +(local client (autoload :conjure.client)) +(local log (autoload :conjure.log)) +(local ts (autoload :conjure.tree-sitter)) (config.merge {:client @@ -30,26 +27,24 @@ :stop "cS" :interrupt "ei"}}}}})) -(def- cfg (config.get-in-fn [:client :scheme :stdio])) +(local cfg (config.get-in-fn [:client :scheme :stdio])) +(local state (client.new-state #(do {:repl nil}))) +(local buf-suffix ".scm") +(local comment-prefix "; ") +(local form-node? ts.node-surrounded-by-form-pair-chars?) -(defonce- state (client.new-state #(do {:repl nil}))) - -(def buf-suffix ".scm") -(def comment-prefix "; ") -(def form-node? ts.node-surrounded-by-form-pair-chars?) - -(defn- with-repl-or-warn [f opts] +(fn with-repl-or-warn [f opts] (let [repl (state :repl)] (if repl (f repl) (log.append [(.. comment-prefix "No REPL running")])))) -(defn unbatch [msgs] +(fn unbatch [msgs] {:out (->> msgs (a.map #(or (a.get $1 :out) (a.get $1 :err))) (str.join ""))}) -(defn format-msg [msg] +(fn format-msg [msg] (->> (-> msg (a.get :out) (string.gsub "^%s*" "") @@ -67,7 +62,7 @@ (.. comment-prefix "(out) " line)))) (a.filter #(not (str.blank? $1))))) -(defn eval-str [opts] +(fn eval-str [opts] (with-repl-or-warn (fn [repl] (repl.send @@ -78,24 +73,24 @@ (log.append msgs))) {:batch? true})))) -(defn eval-file [opts] +(fn eval-file [opts] (eval-str (a.assoc opts :code (.. "(load \"" opts.file-path "\")")))) -(defn- display-repl-status [status] +(fn display-repl-status [status] (log.append [(.. comment-prefix (cfg [:command]) " (" (or status "no status") ")")] {:break? true})) -(defn stop [] +(fn stop [] (let [repl (state :repl)] (when repl (repl.destroy) (display-repl-status :stopped) (a.assoc (state) :repl nil)))) -(defn start [] +(fn start [] (if (state :repl) (log.append [(.. comment-prefix "Can't start, REPL is already running.") (.. comment-prefix "Stop the REPL with " @@ -128,16 +123,16 @@ (fn [msg] (log.append (format-msg msg)))})))) -(defn interrupt [] +(fn interrupt [] (with-repl-or-warn (fn [repl] (log.append [(.. comment-prefix " Sending interrupt signal.")] {:break? true}) (repl.send-signal vim.loop.constants.SIGINT)))) -(defn on-load [] +(fn on-load [] (start)) -(defn on-filetype [] +(fn on-filetype [] (mapping.buf :SchemeStart (cfg [:mapping :start]) start @@ -153,8 +148,19 @@ interrupt {:desc "Interrupt the REPL"})) -(defn on-exit [] +(fn on-exit [] (stop)) - -*module* +{: buf-suffix + : comment-prefix + : form-node? + : unbatch + : format-msg + : eval-str + : eval-file + : stop + : start + : interrupt + : on-load + : on-filetype + : on-exit } diff --git a/lua/conjure/client/scheme/stdio.lua b/lua/conjure/client/scheme/stdio.lua index 6eb2f136..59530b8b 100644 --- a/lua/conjure/client/scheme/stdio.lua +++ b/lua/conjure/client/scheme/stdio.lua @@ -1,52 +1,29 @@ -- [nfnl] Compiled from fnl/conjure/client/scheme/stdio.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.client.scheme.stdio" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, client, config, log, mapping, nvim, stdio, str, ts, _ = autoload("conjure.aniseed.core"), autoload("conjure.client"), autoload("conjure.config"), autoload("conjure.log"), autoload("conjure.mapping"), autoload("conjure.aniseed.nvim"), autoload("conjure.remote.stdio"), autoload("conjure.aniseed.string"), autoload("conjure.tree-sitter"), nil -_2amodule_locals_2a["a"] = a -_2amodule_locals_2a["client"] = client -_2amodule_locals_2a["config"] = config -_2amodule_locals_2a["log"] = log -_2amodule_locals_2a["mapping"] = mapping -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["stdio"] = stdio -_2amodule_locals_2a["str"] = str -_2amodule_locals_2a["ts"] = ts -_2amodule_locals_2a["_"] = _ -do local _ = {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local str = autoload("conjure.aniseed.string") +local stdio = autoload("conjure.remote.stdio") +local config = autoload("conjure.config") +local text = autoload("conjure.text") +local mapping = autoload("conjure.mapping") +local client = autoload("conjure.client") +local log = autoload("conjure.log") +local ts = autoload("conjure.tree-sitter") config.merge({client = {scheme = {stdio = {command = "mit-scheme", prompt_pattern = "[%]e][=r]r?o?r?> ", value_prefix_pattern = "^;Value: "}}}}) if config["get-in"]({"mapping", "enable_defaults"}) then config.merge({client = {scheme = {stdio = {mapping = {start = "cs", stop = "cS", interrupt = "ei"}}}}}) else end local cfg = config["get-in-fn"]({"client", "scheme", "stdio"}) -do end (_2amodule_locals_2a)["cfg"] = cfg -do local _ = {nil, nil} end local state -local function _2_() +local function _3_() return {repl = nil} end -state = ((_2amodule_2a).state or client["new-state"](_2_)) -do end (_2amodule_locals_2a)["state"] = state -do local _ = {nil, nil} end +state = client["new-state"](_3_) local buf_suffix = ".scm" -_2amodule_2a["buf-suffix"] = buf_suffix -do local _ = {nil, nil} end local comment_prefix = "; " -_2amodule_2a["comment-prefix"] = comment_prefix -do local _ = {nil, nil} end local form_node_3f = ts["node-surrounded-by-form-pair-chars?"] -_2amodule_2a["form-node?"] = form_node_3f -do local _ = {nil, nil} end local function with_repl_or_warn(f, opts) local repl = state("repl") if repl then @@ -55,21 +32,17 @@ local function with_repl_or_warn(f, opts) return log.append({(comment_prefix .. "No REPL running")}) end end -_2amodule_locals_2a["with-repl-or-warn"] = with_repl_or_warn -do local _ = {with_repl_or_warn, nil} end local function unbatch(msgs) - local function _4_(_241) + local function _5_(_241) return (a.get(_241, "out") or a.get(_241, "err")) end - return {out = str.join("", a.map(_4_, msgs))} + return {out = str.join("", a.map(_5_, msgs))} end -_2amodule_2a["unbatch"] = unbatch -do local _ = {unbatch, nil} end local function format_msg(msg) - local function _5_(_241) + local function _6_(_241) return not str["blank?"](_241) end - local function _6_(line) + local function _7_(line) if not cfg({"value_prefix_pattern"}) then return line elseif string.match(line, cfg({"value_prefix_pattern"})) then @@ -78,33 +51,25 @@ local function format_msg(msg) return (comment_prefix .. "(out) " .. line) end end - return a.filter(_5_, a.map(_6_, str.split(string.gsub(string.gsub(a.get(msg, "out"), "^%s*", ""), "%s+%d+%s*$", ""), "\n"))) + return a.filter(_6_, a.map(_7_, str.split(string.gsub(string.gsub(a.get(msg, "out"), "^%s*", ""), "%s+%d+%s*$", ""), "\n"))) end -_2amodule_2a["format-msg"] = format_msg -do local _ = {format_msg, nil} end local function eval_str(opts) - local function _8_(repl) - local function _9_(msgs) + local function _9_(repl) + local function _10_(msgs) local msgs0 = format_msg(unbatch(msgs)) opts["on-result"](a.last(msgs0)) return log.append(msgs0) end - return repl.send((opts.code .. "\n"), _9_, {["batch?"] = true}) + return repl.send((opts.code .. "\n"), _10_, {["batch?"] = true}) end - return with_repl_or_warn(_8_) + return with_repl_or_warn(_9_) end -_2amodule_2a["eval-str"] = eval_str -do local _ = {eval_str, nil} end local function eval_file(opts) return eval_str(a.assoc(opts, "code", ("(load \"" .. opts["file-path"] .. "\")"))) end -_2amodule_2a["eval-file"] = eval_file -do local _ = {eval_file, nil} end local function display_repl_status(status) return log.append({(comment_prefix .. cfg({"command"}) .. " (" .. (status or "no status") .. ")")}, {["break?"] = true}) end -_2amodule_locals_2a["display-repl-status"] = display_repl_status -do local _ = {display_repl_status, nil} end local function stop() local repl = state("repl") if repl then @@ -115,19 +80,17 @@ local function stop() return nil end end -_2amodule_2a["stop"] = stop -do local _ = {stop, nil} end local function start() if state("repl") then return log.append({(comment_prefix .. "Can't start, REPL is already running."), (comment_prefix .. "Stop the REPL with " .. config["get-in"]({"mapping", "prefix"}) .. cfg({"mapping", "stop"}))}, {["break?"] = true}) else - local function _11_() + local function _12_() return display_repl_status("started") end - local function _12_(err) + local function _13_(err) return display_repl_status(err) end - local function _13_(code, signal) + local function _14_(code, signal) if (("number" == type(code)) and (code > 0)) then log.append({(comment_prefix .. "process exited with code " .. code)}) else @@ -138,38 +101,28 @@ local function start() end return stop() end - local function _16_(msg) + local function _17_(msg) return log.append(format_msg(msg)) end - return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt_pattern"}), cmd = cfg({"command"}), ["on-success"] = _11_, ["on-error"] = _12_, ["on-exit"] = _13_, ["on-stray-output"] = _16_})) + return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt_pattern"}), cmd = cfg({"command"}), ["on-success"] = _12_, ["on-error"] = _13_, ["on-exit"] = _14_, ["on-stray-output"] = _17_})) end end -_2amodule_2a["start"] = start -do local _ = {start, nil} end local function interrupt() - local function _18_(repl) + local function _19_(repl) log.append({(comment_prefix .. " Sending interrupt signal.")}, {["break?"] = true}) return repl["send-signal"](vim.loop.constants.SIGINT) end - return with_repl_or_warn(_18_) + return with_repl_or_warn(_19_) end -_2amodule_2a["interrupt"] = interrupt -do local _ = {interrupt, nil} end local function on_load() return start() end -_2amodule_2a["on-load"] = on_load -do local _ = {on_load, nil} end local function on_filetype() mapping.buf("SchemeStart", cfg({"mapping", "start"}), start, {desc = "Start the REPL"}) mapping.buf("SchemeStop", cfg({"mapping", "stop"}), stop, {desc = "Stop the REPL"}) return mapping.buf("SchemeInterrupt", cfg({"mapping", "interrupt"}), interrupt, {desc = "Interrupt the REPL"}) end -_2amodule_2a["on-filetype"] = on_filetype -do local _ = {on_filetype, nil} end local function on_exit() return stop() end -_2amodule_2a["on-exit"] = on_exit -do local _ = {on_exit, nil} end -return _2amodule_2a +return {["buf-suffix"] = buf_suffix, ["comment-prefix"] = comment_prefix, ["form-node?"] = form_node_3f, unbatch = unbatch, ["format-msg"] = format_msg, ["eval-str"] = eval_str, ["eval-file"] = eval_file, stop = stop, start = start, interrupt = interrupt, ["on-load"] = on_load, ["on-filetype"] = on_filetype, ["on-exit"] = on_exit} From 745efcff8e8cdb5f8878be7780eff6de89d26036 Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Tue, 27 Aug 2024 14:36:10 -1000 Subject: [PATCH 06/13] Convert Hy client but not tested --- fnl/conjure/client/hy/stdio.fnl | 77 +++++++++-------- lua/conjure/client/hy/stdio.lua | 149 +++++++++++--------------------- 2 files changed, 90 insertions(+), 136 deletions(-) diff --git a/fnl/conjure/client/hy/stdio.fnl b/fnl/conjure/client/hy/stdio.fnl index 81dd03cf..a5853793 100644 --- a/fnl/conjure/client/hy/stdio.fnl +++ b/fnl/conjure/client/hy/stdio.fnl @@ -1,18 +1,14 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) - -(module conjure.client.hy.stdio - {autoload {a conjure.aniseed.core - extract conjure.extract - str conjure.aniseed.string - nvim conjure.aniseed.nvim - stdio conjure.remote.stdio - config conjure.config - text conjure.text - mapping conjure.mapping - client conjure.client - log conjure.log - ts conjure.tree-sitter} - require-macros [conjure.macros]}) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local extract (autoload :conjure.extract)) +(local str (autoload :conjure.aniseed.string)) +(local stdio (autoload :conjure.remote.stdio)) +(local config (autoload :conjure.config)) +(local text (autoload :conjure.text)) +(local mapping (autoload :conjure.mapping)) +(local client (autoload :conjure.client)) +(local log (autoload :conjure.log)) +(local ts (autoload :conjure.tree-sitter)) (config.merge {:client @@ -31,15 +27,13 @@ :stop "cS" :interrupt "ei"}}}}})) -(def- cfg (config.get-in-fn [:client :hy :stdio])) +(local cfg (config.get-in-fn [:client :hy :stdio])) +(local state (client.new-state #(do {:repl nil}))) +(local buf-suffix ".hy") +(local comment-prefix "; ") +(local form-node? ts.node-surrounded-by-form-pair-chars?) -(defonce- state (client.new-state #(do {:repl nil}))) - -(def buf-suffix ".hy") -(def comment-prefix "; ") -(def form-node? ts.node-surrounded-by-form-pair-chars?) - -(defn- with-repl-or-warn [f opts] +(fn with-repl-or-warn [f opts] (let [repl (state :repl)] (if repl (f repl) @@ -49,7 +43,7 @@ (config.get-in [:mapping :prefix]) (cfg [:mapping :start]))])))) -(defn- display-result [msg] +(fn display-result [msg] (let [prefix (if (= true (cfg [:eval :raw_out])) "" (.. comment-prefix (if msg.err "(err)" "(out)") " "))] @@ -58,10 +52,10 @@ (a.map #(.. prefix $1)) log.append))) -(defn- prep-code [s] +(fn prep-code [s] (.. s "\n")) -(defn eval-str [opts] +(fn eval-str [opts] (var last-value nil) (with-repl-or-warn (fn [repl] @@ -82,10 +76,10 @@ (when opts.on-result (opts.on-result last-value))))))))) -(defn eval-file [opts] +(fn eval-file [opts] (log.append [(.. comment-prefix "Not implemented")])) -(defn doc-str [opts] +(fn doc-str [opts] (let [obj (when (= "." (string.sub opts.code 1 1)) (extract.prompt "Specify object or module: ")) obj (.. (or obj "") opts.code) @@ -102,21 +96,21 @@ (.. comment-prefix (if msg.err "(err) " "(doc) ")))))))))) -(defn- display-repl-status [status] +(fn display-repl-status [status] (let [repl (state :repl)] (when repl (log.append [(.. comment-prefix (a.pr-str (a.get-in repl [:opts :cmd])) " (" status ")")] {:break? true})))) -(defn stop [] +(fn stop [] (let [repl (state :repl)] (when repl (repl.destroy) (display-repl-status :stopped) (a.assoc (state) :repl nil)))) -(defn start [] +(fn start [] (if (state :repl) (log.append [(.. comment-prefix "Can't start, REPL is already running.") (.. comment-prefix "Stop the REPL with " @@ -153,20 +147,20 @@ (fn [msg] (display-result msg))})))) -(defn on-load [] +(fn on-load [] (start)) -(defn on-exit [] +(fn on-exit [] (stop)) -(defn interrupt [] +(fn interrupt [] (log.dbg "sending interrupt message" "") (with-repl-or-warn (fn [repl] (log.append [(.. comment-prefix " Sending interrupt signal.")] {:break? true}) (repl.send-signal vim.loop.constants.SIGINT)))) -(defn on-filetype [] +(fn on-filetype [] (mapping.buf :HyStart (cfg [:mapping :start]) start @@ -182,4 +176,15 @@ interrupt {:desc "Interrupt the current evaluation"})) -*module* +{: buf-suffix + : comment-prefix + : form-node? + : eval-str + : eval-file + : doc-str + : stop + : start + : on-load + : on-exit + : interrupt + : on-filetype} diff --git a/lua/conjure/client/hy/stdio.lua b/lua/conjure/client/hy/stdio.lua index 0e5f876b..1db2fcdd 100644 --- a/lua/conjure/client/hy/stdio.lua +++ b/lua/conjure/client/hy/stdio.lua @@ -1,53 +1,30 @@ -- [nfnl] Compiled from fnl/conjure/client/hy/stdio.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.client.hy.stdio" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, client, config, extract, log, mapping, nvim, stdio, str, text, ts, _ = autoload("conjure.aniseed.core"), autoload("conjure.client"), autoload("conjure.config"), autoload("conjure.extract"), autoload("conjure.log"), autoload("conjure.mapping"), autoload("conjure.aniseed.nvim"), autoload("conjure.remote.stdio"), autoload("conjure.aniseed.string"), autoload("conjure.text"), autoload("conjure.tree-sitter"), nil -_2amodule_locals_2a["a"] = a -_2amodule_locals_2a["client"] = client -_2amodule_locals_2a["config"] = config -_2amodule_locals_2a["extract"] = extract -_2amodule_locals_2a["log"] = log -_2amodule_locals_2a["mapping"] = mapping -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["stdio"] = stdio -_2amodule_locals_2a["str"] = str -_2amodule_locals_2a["text"] = text -_2amodule_locals_2a["ts"] = ts -_2amodule_locals_2a["_"] = _ +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local extract = autoload("conjure.extract") +local str = autoload("conjure.aniseed.string") +local stdio = autoload("conjure.remote.stdio") +local config = autoload("conjure.config") +local text = autoload("conjure.text") +local mapping = autoload("conjure.mapping") +local client = autoload("conjure.client") +local log = autoload("conjure.log") +local ts = autoload("conjure.tree-sitter") config.merge({client = {hy = {stdio = {eval = {raw_out = false}, command = "hy -iu -c=\"Ready!\"", prompt_pattern = "=> "}}}}) if config["get-in"]({"mapping", "enable_defaults"}) then config.merge({client = {hy = {stdio = {mapping = {start = "cs", stop = "cS", interrupt = "ei"}}}}}) else end local cfg = config["get-in-fn"]({"client", "hy", "stdio"}) -do end (_2amodule_locals_2a)["cfg"] = cfg -do local _ = {nil, nil} end local state -local function _2_() +local function _3_() return {repl = nil} end -state = ((_2amodule_2a).state or client["new-state"](_2_)) -do end (_2amodule_locals_2a)["state"] = state -do local _ = {nil, nil} end +state = client["new-state"](_3_) local buf_suffix = ".hy" -_2amodule_2a["buf-suffix"] = buf_suffix -do local _ = {nil, nil} end local comment_prefix = "; " -_2amodule_2a["comment-prefix"] = comment_prefix -do local _ = {nil, nil} end local form_node_3f = ts["node-surrounded-by-form-pair-chars?"] -_2amodule_2a["form-node?"] = form_node_3f -do local _ = {nil, nil} end local function with_repl_or_warn(f, opts) local repl = state("repl") if repl then @@ -56,47 +33,40 @@ local function with_repl_or_warn(f, opts) return log.append({(comment_prefix .. "No REPL running"), (comment_prefix .. "Start REPL with " .. config["get-in"]({"mapping", "prefix"}) .. cfg({"mapping", "start"}))}) end end -_2amodule_locals_2a["with-repl-or-warn"] = with_repl_or_warn -do local _ = {with_repl_or_warn, nil} end local function display_result(msg) local prefix if (true == cfg({"eval", "raw_out"})) then prefix = "" else - local function _4_() - if msg.err then - return "(err)" - else - return "(out)" - end + local _5_ + if msg.err then + _5_ = "(err)" + else + _5_ = "(out)" end - prefix = (comment_prefix .. _4_() .. " ") + prefix = (comment_prefix .. _5_ .. " ") end - local function _6_(_241) + local function _8_(_241) return (prefix .. _241) end - local function _7_(_241) + local function _9_(_241) return ("" ~= _241) end - return log.append(a.map(_6_, a.filter(_7_, str.split((msg.err or msg.out), "\n")))) + return log.append(a.map(_8_, a.filter(_9_, str.split((msg.err or msg.out), "\n")))) end -_2amodule_locals_2a["display-result"] = display_result -do local _ = {display_result, nil} end local function prep_code(s) return (s .. "\n") end -_2amodule_locals_2a["prep-code"] = prep_code -do local _ = {prep_code, nil} end local function eval_str(opts) local last_value = nil - local function _8_(repl) - local function _9_(msg) + local function _10_(repl) + local function _11_(msg) log.dbg("msg", msg) local msgs - local function _10_(_241) + local function _12_(_241) return not ("" == _241) end - msgs = a.filter(_10_, str.split((msg.err or msg.out), "\n")) + msgs = a.filter(_12_, str.split((msg.err or msg.out), "\n")) last_value = (a.last(msgs) or last_value) display_result(msg) if msg["done?"] then @@ -110,17 +80,13 @@ local function eval_str(opts) return nil end end - return repl.send(prep_code(opts.code), _9_) + return repl.send(prep_code(opts.code), _11_) end - return with_repl_or_warn(_8_) + return with_repl_or_warn(_10_) end -_2amodule_2a["eval-str"] = eval_str -do local _ = {eval_str, nil} end local function eval_file(opts) return log.append({(comment_prefix .. "Not implemented")}) end -_2amodule_2a["eval-file"] = eval_file -do local _ = {eval_file, nil} end local function doc_str(opts) local obj if ("." == string.sub(opts.code, 1, 1)) then @@ -130,23 +96,20 @@ local function doc_str(opts) end local obj0 = ((obj or "") .. opts.code) local code = ("(if (in (mangle '" .. obj0 .. ") --macros--)\n (doc " .. obj0 .. ")\n (help " .. obj0 .. "))") - local function _14_(repl) - local function _15_(msg) - local function _16_() - if msg.err then - return "(err) " - else - return "(doc) " - end + local function _16_(repl) + local function _17_(msg) + local _18_ + if msg.err then + _18_ = "(err) " + else + _18_ = "(doc) " end - return log.append(text["prefixed-lines"]((msg.err or msg.out), (comment_prefix .. _16_()))) + return log.append(text["prefixed-lines"]((msg.err or msg.out), (comment_prefix .. _18_))) end - return repl.send(prep_code(code), _15_) + return repl.send(prep_code(code), _17_) end - return with_repl_or_warn(_14_) + return with_repl_or_warn(_16_) end -_2amodule_2a["doc-str"] = doc_str -do local _ = {doc_str, nil} end local function display_repl_status(status) local repl = state("repl") if repl then @@ -155,8 +118,6 @@ local function display_repl_status(status) return nil end end -_2amodule_locals_2a["display-repl-status"] = display_repl_status -do local _ = {display_repl_status, nil} end local function stop() local repl = state("repl") if repl then @@ -167,23 +128,21 @@ local function stop() return nil end end -_2amodule_2a["stop"] = stop -do local _ = {stop, nil} end local function start() if state("repl") then return log.append({(comment_prefix .. "Can't start, REPL is already running."), (comment_prefix .. "Stop the REPL with " .. config["get-in"]({"mapping", "prefix"}) .. cfg({"mapping", "stop"}))}, {["break?"] = true}) else - local function _19_() + local function _22_() display_repl_status("started") - local function _20_(repl) + local function _23_(repl) return repl.send(prep_code("(import sys) (setv sys.ps2 \"\") (del sys)")) end - return with_repl_or_warn(_20_) + return with_repl_or_warn(_23_) end - local function _21_(err) + local function _24_(err) return display_repl_status(err) end - local function _22_(code, signal) + local function _25_(code, signal) if (("number" == type(code)) and (code > 0)) then log.append({(comment_prefix .. "process exited with code " .. code)}) else @@ -194,39 +153,29 @@ local function start() end return stop() end - local function _25_(msg) + local function _28_(msg) return display_result(msg) end - return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt_pattern"}), cmd = cfg({"command"}), ["on-success"] = _19_, ["on-error"] = _21_, ["on-exit"] = _22_, ["on-stray-output"] = _25_})) + return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt_pattern"}), cmd = cfg({"command"}), ["on-success"] = _22_, ["on-error"] = _24_, ["on-exit"] = _25_, ["on-stray-output"] = _28_})) end end -_2amodule_2a["start"] = start -do local _ = {start, nil} end local function on_load() return start() end -_2amodule_2a["on-load"] = on_load -do local _ = {on_load, nil} end local function on_exit() return stop() end -_2amodule_2a["on-exit"] = on_exit -do local _ = {on_exit, nil} end local function interrupt() log.dbg("sending interrupt message", "") - local function _27_(repl) + local function _30_(repl) log.append({(comment_prefix .. " Sending interrupt signal.")}, {["break?"] = true}) return repl["send-signal"](vim.loop.constants.SIGINT) end - return with_repl_or_warn(_27_) + return with_repl_or_warn(_30_) end -_2amodule_2a["interrupt"] = interrupt -do local _ = {interrupt, nil} end local function on_filetype() mapping.buf("HyStart", cfg({"mapping", "start"}), start, {desc = "Start the REPL"}) mapping.buf("HyStop", cfg({"mapping", "stop"}), stop, {desc = "Stop the REPL"}) return mapping.buf("HyInterrupt", cfg({"mapping", "interrupt"}), interrupt, {desc = "Interrupt the current evaluation"}) end -_2amodule_2a["on-filetype"] = on_filetype -do local _ = {on_filetype, nil} end -return _2amodule_2a +return {["buf-suffix"] = buf_suffix, ["comment-prefix"] = comment_prefix, ["form-node?"] = form_node_3f, ["eval-str"] = eval_str, ["eval-file"] = eval_file, ["doc-str"] = doc_str, stop = stop, start = start, ["on-load"] = on_load, ["on-exit"] = on_exit, interrupt = interrupt, ["on-filetype"] = on_filetype} From 32f19d56ef772584441bf69907d58cb4f7799a7d Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Tue, 27 Aug 2024 14:45:11 -1000 Subject: [PATCH 07/13] Convert Julia client but not tested --- fnl/conjure/client/julia/stdio.fnl | 81 ++++++++++--------- lua/conjure/client/julia/stdio.lua | 124 +++++++++-------------------- 2 files changed, 80 insertions(+), 125 deletions(-) diff --git a/fnl/conjure/client/julia/stdio.fnl b/fnl/conjure/client/julia/stdio.fnl index 8151b413..68add2ff 100644 --- a/fnl/conjure/client/julia/stdio.fnl +++ b/fnl/conjure/client/julia/stdio.fnl @@ -1,18 +1,14 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) - -(module conjure.client.julia.stdio - {autoload {a conjure.aniseed.core - extract conjure.extract - str conjure.aniseed.string - nvim conjure.aniseed.nvim - stdio conjure.remote.stdio - config conjure.config - text conjure.text - mapping conjure.mapping - client conjure.client - log conjure.log - ts conjure.tree-sitter} - require-macros [conjure.macros]}) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local extract (autoload :conjure.extract)) +(local str (autoload :conjure.aniseed.string)) +(local stdio (autoload :conjure.remote.stdio)) +(local config (autoload :conjure.config)) +(local text (autoload :conjure.text)) +(local mapping (autoload :conjure.mapping)) +(local client (autoload :conjure.client)) +(local log (autoload :conjure.log)) +(local ts (autoload :conjure.tree-sitter)) ; TODO prompt_pattern for julia seems to not show, empty "" is problematic. (config.merge @@ -31,14 +27,12 @@ :stop "cS" :interrupt "ei"}}}}})) -(def- cfg (config.get-in-fn [:client :julia :stdio])) +(local cfg (config.get-in-fn [:client :julia :stdio])) +(local state (client.new-state #(do {:repl nil}))) +(local buf-suffix ".jl") +(local comment-prefix "# ") -(defonce- state (client.new-state #(do {:repl nil}))) - -(def buf-suffix ".jl") -(def comment-prefix "# ") - -(defn- with-repl-or-warn [f opts] +(fn with-repl-or-warn [f opts] (let [repl (state :repl)] (if repl (f repl) @@ -48,21 +42,21 @@ (config.get-in [:mapping :prefix]) (cfg [:mapping :start]))])))) -(defn- prep-code [s] +(fn prep-code [s] (.. s "\nif(isnothing(ans)) display(nothing) end\n")) -(defn unbatch [msgs] +(fn unbatch [msgs] (->> msgs (a.map #(or (a.get $1 :out) (a.get $1 :err))) (str.join ""))) -(defn format-msg [msg] +(fn format-msg [msg] ; remove last "nothing" if preceded by character or newline. (->> (-> (string.gsub msg "(.?[%w\n])(nothing)" "%1") (str.split "\n")) (a.filter #(~= "" $1)))) -(defn get-form-modifier [node] +(fn get-form-modifier [node] ;; When the next sibling is a semi-colon it means we need to override the ;; tree sitter response. We instead need to tell Conjure the exact text and ;; range we're interested in since this is a pretty non-standard operation @@ -79,7 +73,7 @@ ;; Increment the end of the range by one. :range (a.update-in (ts.range node) [:end 2] a.inc)}})) -(defn eval-str [opts] +(fn eval-str [opts] (with-repl-or-warn (fn [repl] (repl.send @@ -91,27 +85,27 @@ (opts.on-result (str.join " " msgs))))) {:batch? true})))) -(defn eval-file [opts] +(fn eval-file [opts] (eval-str (a.assoc opts :code (a.slurp opts.file-path)))) -(defn doc-str [opts] +(fn doc-str [opts] (eval-str (a.update opts :code #(.. "Main.eval(REPL.helpmode(\"" $1 "\"))")))) -(defn- display-repl-status [status] +(fn display-repl-status [status] (let [repl (state :repl)] (when repl (log.append [(.. comment-prefix (a.pr-str (a.get-in repl [:opts :cmd])) " (" status ")")] {:break? true})))) -(defn stop [] +(fn stop [] (let [repl (state :repl)] (when repl (repl.destroy) (display-repl-status :stopped) (a.assoc (state) :repl nil)))) -(defn start [] +(fn start [] (if (state :repl) (log.append [(.. comment-prefix "Can't start, REPL is already running.") (.. comment-prefix "Stop the REPL with " @@ -151,19 +145,19 @@ (fn [msg] (log.append (-> [msg] unbatch format-msg) {:join-first? true}))})))) -(defn on-load [] +(fn on-load [] (start)) -(defn on-exit [] +(fn on-exit [] (stop)) -(defn interrupt [] +(fn interrupt [] (with-repl-or-warn (fn [repl] (log.append [(.. comment-prefix " Sending interrupt signal.")] {:break? true}) (repl.send-signal vim.loop.constants.SIGINT)))) -(defn on-filetype [] +(fn on-filetype [] (mapping.buf :JuliaStart (cfg [:mapping :start]) start @@ -179,4 +173,17 @@ interrupt {:desc "Interrupt the evaluation"})) -*module* +{: buf-suffix + : comment-prefix + : unbatch + : format-msg + : get-form-modifier + : eval-str + : eval-file + : doc-str + : stop + : start + : on-load + : on-exit + : interrupt + : on-filetype} diff --git a/lua/conjure/client/julia/stdio.lua b/lua/conjure/client/julia/stdio.lua index eaefdca0..8011e2a1 100644 --- a/lua/conjure/client/julia/stdio.lua +++ b/lua/conjure/client/julia/stdio.lua @@ -1,51 +1,29 @@ -- [nfnl] Compiled from fnl/conjure/client/julia/stdio.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.client.julia.stdio" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, client, config, extract, log, mapping, nvim, stdio, str, text, ts, _ = autoload("conjure.aniseed.core"), autoload("conjure.client"), autoload("conjure.config"), autoload("conjure.extract"), autoload("conjure.log"), autoload("conjure.mapping"), autoload("conjure.aniseed.nvim"), autoload("conjure.remote.stdio"), autoload("conjure.aniseed.string"), autoload("conjure.text"), autoload("conjure.tree-sitter"), nil -_2amodule_locals_2a["a"] = a -_2amodule_locals_2a["client"] = client -_2amodule_locals_2a["config"] = config -_2amodule_locals_2a["extract"] = extract -_2amodule_locals_2a["log"] = log -_2amodule_locals_2a["mapping"] = mapping -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["stdio"] = stdio -_2amodule_locals_2a["str"] = str -_2amodule_locals_2a["text"] = text -_2amodule_locals_2a["ts"] = ts -_2amodule_locals_2a["_"] = _ -do local _ = {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local extract = autoload("conjure.extract") +local str = autoload("conjure.aniseed.string") +local stdio = autoload("conjure.remote.stdio") +local config = autoload("conjure.config") +local text = autoload("conjure.text") +local mapping = autoload("conjure.mapping") +local client = autoload("conjure.client") +local log = autoload("conjure.log") +local ts = autoload("conjure.tree-sitter") config.merge({client = {julia = {stdio = {command = "julia --banner=no --color=no -i", prompt_pattern = ""}}}}) if config["get-in"]({"mapping", "enable_defaults"}) then config.merge({client = {julia = {stdio = {mapping = {start = "cs", stop = "cS", interrupt = "ei"}}}}}) else end local cfg = config["get-in-fn"]({"client", "julia", "stdio"}) -do end (_2amodule_locals_2a)["cfg"] = cfg -do local _ = {nil, nil} end local state -local function _2_() +local function _3_() return {repl = nil} end -state = ((_2amodule_2a).state or client["new-state"](_2_)) -do end (_2amodule_locals_2a)["state"] = state -do local _ = {nil, nil} end +state = client["new-state"](_3_) local buf_suffix = ".jl" -_2amodule_2a["buf-suffix"] = buf_suffix -do local _ = {nil, nil} end local comment_prefix = "# " -_2amodule_2a["comment-prefix"] = comment_prefix -do local _ = {nil, nil} end local function with_repl_or_warn(f, opts) local repl = state("repl") if repl then @@ -54,29 +32,21 @@ local function with_repl_or_warn(f, opts) return log.append({(comment_prefix .. "No REPL running"), (comment_prefix .. "Start REPL with " .. config["get-in"]({"mapping", "prefix"}) .. cfg({"mapping", "start"}))}) end end -_2amodule_locals_2a["with-repl-or-warn"] = with_repl_or_warn -do local _ = {with_repl_or_warn, nil} end local function prep_code(s) return (s .. "\nif(isnothing(ans)) display(nothing) end\n") end -_2amodule_locals_2a["prep-code"] = prep_code -do local _ = {prep_code, nil} end local function unbatch(msgs) - local function _4_(_241) + local function _5_(_241) return (a.get(_241, "out") or a.get(_241, "err")) end - return str.join("", a.map(_4_, msgs)) + return str.join("", a.map(_5_, msgs)) end -_2amodule_2a["unbatch"] = unbatch -do local _ = {unbatch, nil} end local function format_msg(msg) - local function _5_(_241) + local function _6_(_241) return ("" ~= _241) end - return a.filter(_5_, str.split(string.gsub(msg, "(.?[%w\n])(nothing)", "%1"), "\n")) + return a.filter(_6_, str.split(string.gsub(msg, "(.?[%w\n])(nothing)", "%1"), "\n")) end -_2amodule_2a["format-msg"] = format_msg -do local _ = {format_msg, nil} end local function get_form_modifier(node) if (";" == ts["node->str"](node:next_sibling())) then return {modifier = "raw", ["node-table"] = {content = (ts["node->str"](node) .. ";"), range = a["update-in"](ts.range(node), {"end", 2}, a.inc)}} @@ -84,11 +54,9 @@ local function get_form_modifier(node) return nil end end -_2amodule_2a["get-form-modifier"] = get_form_modifier -do local _ = {get_form_modifier, nil} end local function eval_str(opts) - local function _7_(repl) - local function _8_(msgs) + local function _8_(repl) + local function _9_(msgs) local msgs0 = format_msg(unbatch(msgs)) log.append(msgs0) if opts["on-result"] then @@ -97,25 +65,19 @@ local function eval_str(opts) return nil end end - return repl.send(prep_code(string.gsub(opts.code, ";$", "; nothing;")), _8_, {["batch?"] = true}) + return repl.send(prep_code(string.gsub(opts.code, ";$", "; nothing;")), _9_, {["batch?"] = true}) end - return with_repl_or_warn(_7_) + return with_repl_or_warn(_8_) end -_2amodule_2a["eval-str"] = eval_str -do local _ = {eval_str, nil} end local function eval_file(opts) return eval_str(a.assoc(opts, "code", a.slurp(opts["file-path"]))) end -_2amodule_2a["eval-file"] = eval_file -do local _ = {eval_file, nil} end local function doc_str(opts) - local function _10_(_241) + local function _11_(_241) return ("Main.eval(REPL.helpmode(\"" .. _241 .. "\"))") end - return eval_str(a.update(opts, "code", _10_)) + return eval_str(a.update(opts, "code", _11_)) end -_2amodule_2a["doc-str"] = doc_str -do local _ = {doc_str, nil} end local function display_repl_status(status) local repl = state("repl") if repl then @@ -124,8 +86,6 @@ local function display_repl_status(status) return nil end end -_2amodule_locals_2a["display-repl-status"] = display_repl_status -do local _ = {display_repl_status, nil} end local function stop() local repl = state("repl") if repl then @@ -136,26 +96,24 @@ local function stop() return nil end end -_2amodule_2a["stop"] = stop -do local _ = {stop, nil} end local function start() if state("repl") then return log.append({(comment_prefix .. "Can't start, REPL is already running."), (comment_prefix .. "Stop the REPL with " .. config["get-in"]({"mapping", "prefix"}) .. cfg({"mapping", "stop"}))}, {["break?"] = true}) else - local function _13_() + local function _14_() display_repl_status("started") - local function _14_(repl) - local function _15_(msgs) + local function _15_(repl) + local function _16_(msgs) return log.append(format_msg(unbatch(msgs))) end - return repl.send(prep_code("using REPL"), _15_, {["batch?"] = true}) + return repl.send(prep_code("using REPL"), _16_, {["batch?"] = true}) end - return with_repl_or_warn(_14_) + return with_repl_or_warn(_15_) end - local function _16_(err) + local function _17_(err) return display_repl_status(err) end - local function _17_(code, signal) + local function _18_(code, signal) if (("number" == type(code)) and (code > 0)) then log.append({(comment_prefix .. "process exited with code " .. code)}) else @@ -166,38 +124,28 @@ local function start() end return stop() end - local function _20_(msg) + local function _21_(msg) return log.append(format_msg(unbatch({msg})), {["join-first?"] = true}) end - return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt_pattern"}), cmd = cfg({"command"}), ["on-success"] = _13_, ["on-error"] = _16_, ["on-exit"] = _17_, ["on-stray-output"] = _20_})) + return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt_pattern"}), cmd = cfg({"command"}), ["on-success"] = _14_, ["on-error"] = _17_, ["on-exit"] = _18_, ["on-stray-output"] = _21_})) end end -_2amodule_2a["start"] = start -do local _ = {start, nil} end local function on_load() return start() end -_2amodule_2a["on-load"] = on_load -do local _ = {on_load, nil} end local function on_exit() return stop() end -_2amodule_2a["on-exit"] = on_exit -do local _ = {on_exit, nil} end local function interrupt() - local function _22_(repl) + local function _23_(repl) log.append({(comment_prefix .. " Sending interrupt signal.")}, {["break?"] = true}) return repl["send-signal"](vim.loop.constants.SIGINT) end - return with_repl_or_warn(_22_) + return with_repl_or_warn(_23_) end -_2amodule_2a["interrupt"] = interrupt -do local _ = {interrupt, nil} end local function on_filetype() mapping.buf("JuliaStart", cfg({"mapping", "start"}), start, {desc = "Start the REPL"}) mapping.buf("JuliaStop", cfg({"mapping", "stop"}), stop, {desc = "Stop the REPL"}) return mapping.buf("JuliaInterrupt", cfg({"mapping", "interrupt"}), interrupt, {desc = "Interrupt the evaluation"}) end -_2amodule_2a["on-filetype"] = on_filetype -do local _ = {on_filetype, nil} end -return _2amodule_2a +return {["buf-suffix"] = buf_suffix, ["comment-prefix"] = comment_prefix, unbatch = unbatch, ["format-msg"] = format_msg, ["get-form-modifier"] = get_form_modifier, ["eval-str"] = eval_str, ["eval-file"] = eval_file, ["doc-str"] = doc_str, stop = stop, start = start, ["on-load"] = on_load, ["on-exit"] = on_exit, interrupt = interrupt, ["on-filetype"] = on_filetype} From fa8dac42780cfede304a98f795ebca8ee9d02610 Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Tue, 27 Aug 2024 14:51:16 -1000 Subject: [PATCH 08/13] Convert Janet client but not tested --- fnl/conjure/client/janet/stdio.fnl | 74 +++++++++++--------- lua/conjure/client/janet/stdio.lua | 107 ++++++++--------------------- 2 files changed, 69 insertions(+), 112 deletions(-) diff --git a/fnl/conjure/client/janet/stdio.fnl b/fnl/conjure/client/janet/stdio.fnl index b9fb423c..c2263f3f 100644 --- a/fnl/conjure/client/janet/stdio.fnl +++ b/fnl/conjure/client/janet/stdio.fnl @@ -1,16 +1,13 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) - -(module conjure.client.janet.stdio - {autoload {a conjure.aniseed.core - str conjure.aniseed.string - nvim conjure.aniseed.nvim - stdio conjure.remote.stdio - config conjure.config - mapping conjure.mapping - client conjure.client - log conjure.log - ts conjure.tree-sitter} - require-macros [conjure.macros]}) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local str (autoload :conjure.aniseed.string)) +(local stdio (autoload :conjure.remote.stdio)) +(local config (autoload :conjure.config)) +(local text (autoload :conjure.text)) +(local mapping (autoload :conjure.mapping)) +(local client (autoload :conjure.client)) +(local log (autoload :conjure.log)) +(local ts (autoload :conjure.tree-sitter)) (config.merge {:client @@ -35,33 +32,31 @@ ;;:prompt_pattern "(repl|debug\\[[0-9]+\\]):[0-9]+:[^>]*> " }}}}) -(def- cfg (config.get-in-fn [:client :janet :stdio])) +(local cfg (config.get-in-fn [:client :janet :stdio])) +(local state (client.new-state #(do {:repl nil}))) +(local buf-suffix ".janet") +(local comment-prefix "# ") +(local form-node? ts.node-surrounded-by-form-pair-chars?) -(defonce- state (client.new-state #(do {:repl nil}))) - -(def buf-suffix ".janet") -(def comment-prefix "# ") -(def form-node? ts.node-surrounded-by-form-pair-chars?) - -(defn- with-repl-or-warn [f opts] +(fn with-repl-or-warn [f opts] (let [repl (state :repl)] (if repl (f repl) (log.append [(.. comment-prefix "No REPL running")])))) -(defn unbatch [msgs] +(fn unbatch [msgs] {:out (->> msgs (a.map #(or (a.get $1 :out) (a.get $1 :err))) (str.join ""))}) -(defn- format-message [msg] +(fn format-message [msg] (->> (str.split msg.out "\n") (a.filter #(~= "" $1)))) -(defn- prep-code [s] +(fn prep-code [s] (.. s "\n")) -(defn eval-str [opts] +(fn eval-str [opts] (with-repl-or-warn (fn [repl] (repl.send @@ -73,27 +68,27 @@ (log.append lines))) {:batch? true})))) -(defn eval-file [opts] +(fn eval-file [opts] (eval-str (a.assoc opts :code (a.slurp opts.file-path)))) -(defn doc-str [opts] +(fn doc-str [opts] (eval-str (a.update opts :code #(.. "(doc " $1 ")")))) -(defn- display-repl-status [status] +(fn display-repl-status [status] (let [repl (state :repl)] (when repl (log.append [(.. comment-prefix (a.pr-str (a.get-in repl [:opts :cmd])) " (" status ")")] {:break? true})))) -(defn stop [] +(fn stop [] (let [repl (state :repl)] (when repl (repl.destroy) (display-repl-status :stopped) (a.assoc (state) :repl nil)))) -(defn start [] +(fn start [] (if (state :repl) (log.append [(.. comment-prefix "Can't start, REPL is already running.") (.. comment-prefix "Stop the REPL with " @@ -126,10 +121,10 @@ (fn [msg] (log.append (format-message msg)))})))) -(defn on-load [] +(fn on-load [] (start)) -(defn on-filetype [] +(fn on-filetype [] (mapping.buf :JanetStart (cfg [:mapping :start]) start @@ -140,7 +135,18 @@ stop {:desc "Stop the REPL"})) -(defn on-exit [] +(fn on-exit [] (stop)) -*module* +{: buf-suffix + : comment-prefix + : form-node? + : unbatch + : eval-str + : eval-file + : doc-str + : stop + : start + : on-load + : on-filetype + : on-exit} diff --git a/lua/conjure/client/janet/stdio.lua b/lua/conjure/client/janet/stdio.lua index 2eff779b..b26b11ac 100644 --- a/lua/conjure/client/janet/stdio.lua +++ b/lua/conjure/client/janet/stdio.lua @@ -1,48 +1,25 @@ -- [nfnl] Compiled from fnl/conjure/client/janet/stdio.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.client.janet.stdio" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, client, config, log, mapping, nvim, stdio, str, ts, _ = autoload("conjure.aniseed.core"), autoload("conjure.client"), autoload("conjure.config"), autoload("conjure.log"), autoload("conjure.mapping"), autoload("conjure.aniseed.nvim"), autoload("conjure.remote.stdio"), autoload("conjure.aniseed.string"), autoload("conjure.tree-sitter"), nil -_2amodule_locals_2a["a"] = a -_2amodule_locals_2a["client"] = client -_2amodule_locals_2a["config"] = config -_2amodule_locals_2a["log"] = log -_2amodule_locals_2a["mapping"] = mapping -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["stdio"] = stdio -_2amodule_locals_2a["str"] = str -_2amodule_locals_2a["ts"] = ts -_2amodule_locals_2a["_"] = _ -do local _ = {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local str = autoload("conjure.aniseed.string") +local stdio = autoload("conjure.remote.stdio") +local config = autoload("conjure.config") +local text = autoload("conjure.text") +local mapping = autoload("conjure.mapping") +local client = autoload("conjure.client") +local log = autoload("conjure.log") +local ts = autoload("conjure.tree-sitter") config.merge({client = {janet = {stdio = {mapping = {start = "cs", stop = "cS"}, command = "janet -n -s", prompt_pattern = "repl:[0-9]+:[^>]*> "}}}}) local cfg = config["get-in-fn"]({"client", "janet", "stdio"}) -do end (_2amodule_locals_2a)["cfg"] = cfg -do local _ = {nil, nil} end local state -local function _1_() +local function _2_() return {repl = nil} end -state = ((_2amodule_2a).state or client["new-state"](_1_)) -do end (_2amodule_locals_2a)["state"] = state -do local _ = {nil, nil} end +state = client["new-state"](_2_) local buf_suffix = ".janet" -_2amodule_2a["buf-suffix"] = buf_suffix -do local _ = {nil, nil} end local comment_prefix = "# " -_2amodule_2a["comment-prefix"] = comment_prefix -do local _ = {nil, nil} end local form_node_3f = ts["node-surrounded-by-form-pair-chars?"] -_2amodule_2a["form-node?"] = form_node_3f -do local _ = {nil, nil} end local function with_repl_or_warn(f, opts) local repl = state("repl") if repl then @@ -51,32 +28,24 @@ local function with_repl_or_warn(f, opts) return log.append({(comment_prefix .. "No REPL running")}) end end -_2amodule_locals_2a["with-repl-or-warn"] = with_repl_or_warn -do local _ = {with_repl_or_warn, nil} end local function unbatch(msgs) - local function _3_(_241) + local function _4_(_241) return (a.get(_241, "out") or a.get(_241, "err")) end - return {out = str.join("", a.map(_3_, msgs))} + return {out = str.join("", a.map(_4_, msgs))} end -_2amodule_2a["unbatch"] = unbatch -do local _ = {unbatch, nil} end local function format_message(msg) - local function _4_(_241) + local function _5_(_241) return ("" ~= _241) end - return a.filter(_4_, str.split(msg.out, "\n")) + return a.filter(_5_, str.split(msg.out, "\n")) end -_2amodule_locals_2a["format-message"] = format_message -do local _ = {format_message, nil} end local function prep_code(s) return (s .. "\n") end -_2amodule_locals_2a["prep-code"] = prep_code -do local _ = {prep_code, nil} end local function eval_str(opts) - local function _5_(repl) - local function _6_(msgs) + local function _6_(repl) + local function _7_(msgs) local lines = format_message(unbatch(msgs)) if opts["on-result"] then opts["on-result"](a.last(lines)) @@ -84,25 +53,19 @@ local function eval_str(opts) end return log.append(lines) end - return repl.send(prep_code(opts.code), _6_, {["batch?"] = true}) + return repl.send(prep_code(opts.code), _7_, {["batch?"] = true}) end - return with_repl_or_warn(_5_) + return with_repl_or_warn(_6_) end -_2amodule_2a["eval-str"] = eval_str -do local _ = {eval_str, nil} end local function eval_file(opts) return eval_str(a.assoc(opts, "code", a.slurp(opts["file-path"]))) end -_2amodule_2a["eval-file"] = eval_file -do local _ = {eval_file, nil} end local function doc_str(opts) - local function _8_(_241) + local function _9_(_241) return ("(doc " .. _241 .. ")") end - return eval_str(a.update(opts, "code", _8_)) + return eval_str(a.update(opts, "code", _9_)) end -_2amodule_2a["doc-str"] = doc_str -do local _ = {doc_str, nil} end local function display_repl_status(status) local repl = state("repl") if repl then @@ -111,8 +74,6 @@ local function display_repl_status(status) return nil end end -_2amodule_locals_2a["display-repl-status"] = display_repl_status -do local _ = {display_repl_status, nil} end local function stop() local repl = state("repl") if repl then @@ -123,19 +84,17 @@ local function stop() return nil end end -_2amodule_2a["stop"] = stop -do local _ = {stop, nil} end local function start() if state("repl") then return log.append({(comment_prefix .. "Can't start, REPL is already running."), (comment_prefix .. "Stop the REPL with " .. config["get-in"]({"mapping", "prefix"}) .. cfg({"mapping", "stop"}))}, {["break?"] = true}) else - local function _11_() + local function _12_() return display_repl_status("started") end - local function _12_(err) + local function _13_(err) return display_repl_status(err) end - local function _13_(code, signal) + local function _14_(code, signal) if (("number" == type(code)) and (code > 0)) then log.append({(comment_prefix .. "process exited with code " .. code)}) else @@ -146,28 +105,20 @@ local function start() end return stop() end - local function _16_(msg) + local function _17_(msg) return log.append(format_message(msg)) end - return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt_pattern"}), cmd = cfg({"command"}), ["on-success"] = _11_, ["on-error"] = _12_, ["on-exit"] = _13_, ["on-stray-output"] = _16_})) + return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt_pattern"}), cmd = cfg({"command"}), ["on-success"] = _12_, ["on-error"] = _13_, ["on-exit"] = _14_, ["on-stray-output"] = _17_})) end end -_2amodule_2a["start"] = start -do local _ = {start, nil} end local function on_load() return start() end -_2amodule_2a["on-load"] = on_load -do local _ = {on_load, nil} end local function on_filetype() mapping.buf("JanetStart", cfg({"mapping", "start"}), start, {desc = "Start the REPL"}) return mapping.buf("JanetStop", cfg({"mapping", "stop"}), stop, {desc = "Stop the REPL"}) end -_2amodule_2a["on-filetype"] = on_filetype -do local _ = {on_filetype, nil} end local function on_exit() return stop() end -_2amodule_2a["on-exit"] = on_exit -do local _ = {on_exit, nil} end -return _2amodule_2a +return {["buf-suffix"] = buf_suffix, ["comment-prefix"] = comment_prefix, ["form-node?"] = form_node_3f, unbatch = unbatch, ["eval-str"] = eval_str, ["eval-file"] = eval_file, ["doc-str"] = doc_str, stop = stop, start = start, ["on-load"] = on_load, ["on-filetype"] = on_filetype, ["on-exit"] = on_exit} From b358ab6f0fd5629f334288f6152df057ce270ea6 Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Tue, 27 Aug 2024 15:02:45 -1000 Subject: [PATCH 09/13] Convert Fennel client --- fnl/conjure/client/fennel/stdio.fnl | 80 ++++++++++--------- lua/conjure/client/fennel/stdio.lua | 114 ++++++++-------------------- 2 files changed, 74 insertions(+), 120 deletions(-) diff --git a/fnl/conjure/client/fennel/stdio.fnl b/fnl/conjure/client/fennel/stdio.fnl index c2ac4d88..e2affd5f 100644 --- a/fnl/conjure/client/fennel/stdio.fnl +++ b/fnl/conjure/client/fennel/stdio.fnl @@ -1,18 +1,14 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) - -(module conjure.client.fennel.stdio - {autoload {a conjure.aniseed.core - str conjure.aniseed.string - nvim conjure.aniseed.nvim - stdio conjure.remote.stdio - afs conjure.aniseed.fs - config conjure.config - text conjure.text - mapping conjure.mapping - client conjure.client - log conjure.log - ts conjure.tree-sitter} - require-macros [conjure.macros]}) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local afs (autoload :conjure.aniseed.fs)) +(local str (autoload :conjure.aniseed.string)) +(local stdio (autoload :conjure.remote.stdio)) +(local config (autoload :conjure.config)) +(local text (autoload :conjure.text)) +(local mapping (autoload :conjure.mapping)) +(local client (autoload :conjure.client)) +(local log (autoload :conjure.log)) +(local ts (autoload :conjure.tree-sitter)) (config.merge {:client @@ -30,30 +26,28 @@ :stop "cS" :eval_reload "eF"}}}}})) -(def- cfg (config.get-in-fn [:client :fennel :stdio])) +(local cfg (config.get-in-fn [:client :fennel :stdio])) +(local state (client.new-state #(do {:repl nil}))) +(local buf-suffix ".fnl") +(local comment-prefix "; ") +(local form-node? ts.node-surrounded-by-form-pair-chars?) +(local comment-node? ts.lisp-comment-node?) -(defonce- state (client.new-state #(do {:repl nil}))) - -(def buf-suffix ".fnl") -(def comment-prefix "; ") -(def form-node? ts.node-surrounded-by-form-pair-chars?) -(def comment-node? ts.lisp-comment-node?) - -(defn- with-repl-or-warn [f opts] +(fn with-repl-or-warn [f opts] (let [repl (state :repl)] (if repl (f repl) (log.append [(.. comment-prefix "No REPL running")])))) -(defn- format-message [msg] +(fn format-message [msg] (str.split (or msg.out msg.err) "\n")) -(defn- display-result [msg] +(fn display-result [msg] (log.append (->> (format-message msg) (a.filter #(not (= "" $1)))))) -(defn eval-str [opts] +(fn eval-str [opts] (with-repl-or-warn (fn [repl] (repl.send @@ -69,10 +63,10 @@ (a.run! display-result msgs))) {:batch? true})))) -(defn eval-file [opts] +(fn eval-file [opts] (eval-str (a.assoc opts :code (a.slurp opts.file-path)))) -(defn eval-reload [] +(fn eval-reload [] (let [file-path (nvim.fn.expand "%") relative-no-suf (nvim.fn.fnamemodify file-path ":.:r") module-path (string.gsub relative-no-suf afs.path-sep ".")] @@ -83,24 +77,24 @@ :file-path file-path :code (.. ",reload " module-path)}))) -(defn doc-str [opts] +(fn doc-str [opts] (eval-str (a.update opts :code #(.. ",doc " $1 "\n")))) -(defn- display-repl-status [status] +(fn display-repl-status [status] (let [repl (state :repl)] (when repl (log.append [(.. comment-prefix (a.pr-str (a.get-in repl [:opts :cmd])) " (" status ")")] {:break? true})))) -(defn stop [] +(fn stop [] (let [repl (state :repl)] (when repl (repl.destroy) (display-repl-status :stopped) (a.assoc (state) :repl nil)))) -(defn start [] +(fn start [] (if (state :repl) (log.append [(.. comment-prefix "Can't start, REPL is already running.") (.. comment-prefix "Stop the REPL with " @@ -133,13 +127,13 @@ (fn [msg] (display-result msg))})))) -(defn on-load [] +(fn on-load [] (start)) -(defn on-exit [] +(fn on-exit [] (stop)) -(defn on-filetype [] +(fn on-filetype [] (mapping.buf :FnlStart (cfg [:mapping :start]) @@ -158,4 +152,16 @@ eval-reload {:desc "Use ,reload on the file"})) -*module* +{: buf-suffix + : comment-prefix + : form-node? + : comment-node? + : eval-str + : eval-file + : eval-reload + : doc-str + : stop + : start + : on-load + : on-exit + : on-filetype} diff --git a/lua/conjure/client/fennel/stdio.lua b/lua/conjure/client/fennel/stdio.lua index bccd77fc..20a5e434 100644 --- a/lua/conjure/client/fennel/stdio.lua +++ b/lua/conjure/client/fennel/stdio.lua @@ -1,57 +1,31 @@ -- [nfnl] Compiled from fnl/conjure/client/fennel/stdio.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.client.fennel.stdio" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, afs, client, config, log, mapping, nvim, stdio, str, text, ts, _ = autoload("conjure.aniseed.core"), autoload("conjure.aniseed.fs"), autoload("conjure.client"), autoload("conjure.config"), autoload("conjure.log"), autoload("conjure.mapping"), autoload("conjure.aniseed.nvim"), autoload("conjure.remote.stdio"), autoload("conjure.aniseed.string"), autoload("conjure.text"), autoload("conjure.tree-sitter"), nil -_2amodule_locals_2a["a"] = a -_2amodule_locals_2a["afs"] = afs -_2amodule_locals_2a["client"] = client -_2amodule_locals_2a["config"] = config -_2amodule_locals_2a["log"] = log -_2amodule_locals_2a["mapping"] = mapping -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["stdio"] = stdio -_2amodule_locals_2a["str"] = str -_2amodule_locals_2a["text"] = text -_2amodule_locals_2a["ts"] = ts -_2amodule_locals_2a["_"] = _ -do local _ = {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local afs = autoload("conjure.aniseed.fs") +local str = autoload("conjure.aniseed.string") +local stdio = autoload("conjure.remote.stdio") +local config = autoload("conjure.config") +local text = autoload("conjure.text") +local mapping = autoload("conjure.mapping") +local client = autoload("conjure.client") +local log = autoload("conjure.log") +local ts = autoload("conjure.tree-sitter") config.merge({client = {fennel = {stdio = {command = "fennel", prompt_pattern = ">> "}}}}) if config["get-in"]({"mapping", "enable_defaults"}) then config.merge({client = {fennel = {stdio = {mapping = {start = "cs", stop = "cS", eval_reload = "eF"}}}}}) else end local cfg = config["get-in-fn"]({"client", "fennel", "stdio"}) -do end (_2amodule_locals_2a)["cfg"] = cfg -do local _ = {nil, nil} end local state -local function _2_() +local function _3_() return {repl = nil} end -state = ((_2amodule_2a).state or client["new-state"](_2_)) -do end (_2amodule_locals_2a)["state"] = state -do local _ = {nil, nil} end +state = client["new-state"](_3_) local buf_suffix = ".fnl" -_2amodule_2a["buf-suffix"] = buf_suffix -do local _ = {nil, nil} end local comment_prefix = "; " -_2amodule_2a["comment-prefix"] = comment_prefix -do local _ = {nil, nil} end local form_node_3f = ts["node-surrounded-by-form-pair-chars?"] -_2amodule_2a["form-node?"] = form_node_3f -do local _ = {nil, nil} end local comment_node_3f = ts["lisp-comment-node?"] -_2amodule_2a["comment-node?"] = comment_node_3f -do local _ = {nil, nil} end local function with_repl_or_warn(f, opts) local repl = state("repl") if repl then @@ -60,50 +34,40 @@ local function with_repl_or_warn(f, opts) return log.append({(comment_prefix .. "No REPL running")}) end end -_2amodule_locals_2a["with-repl-or-warn"] = with_repl_or_warn -do local _ = {with_repl_or_warn, nil} end local function format_message(msg) return str.split((msg.out or msg.err), "\n") end -_2amodule_locals_2a["format-message"] = format_message -do local _ = {format_message, nil} end local function display_result(msg) - local function _4_(_241) + local function _5_(_241) return not ("" == _241) end - return log.append(a.filter(_4_, format_message(msg))) + return log.append(a.filter(_5_, format_message(msg))) end -_2amodule_locals_2a["display-result"] = display_result -do local _ = {display_result, nil} end local function eval_str(opts) - local function _5_(repl) - local function _6_(msgs) + local function _6_(repl) + local function _7_(msgs) if ((1 == a.count(msgs)) and ("" == a["get-in"](msgs, {1, "out"}))) then a["assoc-in"](msgs, {1, "out"}, (comment_prefix .. "Empty result.")) else end local msgs0 - local function _8_(_241) - return (".." ~= (_241).out) + local function _9_(_241) + return (".." ~= _241.out) end - msgs0 = a.filter(_8_, msgs) + msgs0 = a.filter(_9_, msgs) if opts["on-result"] then opts["on-result"](str.join("\n", format_message(a.last(msgs0)))) else end return a["run!"](display_result, msgs0) end - return repl.send((opts.code .. "\n"), _6_, {["batch?"] = true}) + return repl.send((opts.code .. "\n"), _7_, {["batch?"] = true}) end - return with_repl_or_warn(_5_) + return with_repl_or_warn(_6_) end -_2amodule_2a["eval-str"] = eval_str -do local _ = {eval_str, nil} end local function eval_file(opts) return eval_str(a.assoc(opts, "code", a.slurp(opts["file-path"]))) end -_2amodule_2a["eval-file"] = eval_file -do local _ = {eval_file, nil} end local function eval_reload() local file_path = nvim.fn.expand("%") local relative_no_suf = nvim.fn.fnamemodify(file_path, ":.:r") @@ -111,16 +75,12 @@ local function eval_reload() log.append({(comment_prefix .. ",reload " .. module_path)}, {["break?"] = true}) return eval_str({action = "eval", origin = "reload", ["file-path"] = file_path, code = (",reload " .. module_path)}) end -_2amodule_2a["eval-reload"] = eval_reload -do local _ = {eval_reload, nil} end local function doc_str(opts) - local function _10_(_241) + local function _11_(_241) return (",doc " .. _241 .. "\n") end - return eval_str(a.update(opts, "code", _10_)) + return eval_str(a.update(opts, "code", _11_)) end -_2amodule_2a["doc-str"] = doc_str -do local _ = {doc_str, nil} end local function display_repl_status(status) local repl = state("repl") if repl then @@ -129,8 +89,6 @@ local function display_repl_status(status) return nil end end -_2amodule_locals_2a["display-repl-status"] = display_repl_status -do local _ = {display_repl_status, nil} end local function stop() local repl = state("repl") if repl then @@ -141,19 +99,17 @@ local function stop() return nil end end -_2amodule_2a["stop"] = stop -do local _ = {stop, nil} end local function start() if state("repl") then return log.append({(comment_prefix .. "Can't start, REPL is already running."), (comment_prefix .. "Stop the REPL with " .. config["get-in"]({"mapping", "prefix"}) .. cfg({"mapping", "stop"}))}, {["break?"] = true}) else - local function _13_() + local function _14_() return display_repl_status("started") end - local function _14_(err) + local function _15_(err) return display_repl_status(err) end - local function _15_(code, signal) + local function _16_(code, signal) if (("number" == type(code)) and (code > 0)) then log.append({(comment_prefix .. "process exited with code " .. code)}) else @@ -164,29 +120,21 @@ local function start() end return stop() end - local function _18_(msg) + local function _19_(msg) return display_result(msg) end - return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt_pattern"}), cmd = cfg({"command"}), ["on-success"] = _13_, ["on-error"] = _14_, ["on-exit"] = _15_, ["on-stray-output"] = _18_})) + return a.assoc(state(), "repl", stdio.start({["prompt-pattern"] = cfg({"prompt_pattern"}), cmd = cfg({"command"}), ["on-success"] = _14_, ["on-error"] = _15_, ["on-exit"] = _16_, ["on-stray-output"] = _19_})) end end -_2amodule_2a["start"] = start -do local _ = {start, nil} end local function on_load() return start() end -_2amodule_2a["on-load"] = on_load -do local _ = {on_load, nil} end local function on_exit() return stop() end -_2amodule_2a["on-exit"] = on_exit -do local _ = {on_exit, nil} end local function on_filetype() mapping.buf("FnlStart", cfg({"mapping", "start"}), start, {desc = "Start the REPL"}) mapping.buf("FnlStop", cfg({"mapping", "stop"}), stop, {desc = "Stop the REPL"}) return mapping.buf("FnlEvalReload", cfg({"mapping", "eval_reload"}), eval_reload, {desc = "Use ,reload on the file"}) end -_2amodule_2a["on-filetype"] = on_filetype -do local _ = {on_filetype, nil} end -return _2amodule_2a +return {["buf-suffix"] = buf_suffix, ["comment-prefix"] = comment_prefix, ["form-node?"] = form_node_3f, ["comment-node?"] = comment_node_3f, ["eval-str"] = eval_str, ["eval-file"] = eval_file, ["eval-reload"] = eval_reload, ["doc-str"] = doc_str, stop = stop, start = start, ["on-load"] = on_load, ["on-exit"] = on_exit, ["on-filetype"] = on_filetype} From 843adc61060182db6888ebe0e9dc3b576dc3b402 Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Tue, 27 Aug 2024 20:30:47 -1000 Subject: [PATCH 10/13] Convert remote/transport/base64 --- .../remote/transport/base64_spec.fnl | 17 +++++++++++++ fnl/conjure/remote/transport/base64.fnl | 11 ++++----- .../remote/transport/base64_spec.lua | 24 +++++++++++++++++++ lua/conjure/remote/transport/base64.lua | 20 ++-------------- 4 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 fnl/conjure-spec/remote/transport/base64_spec.fnl create mode 100644 lua/conjure-spec/remote/transport/base64_spec.lua diff --git a/fnl/conjure-spec/remote/transport/base64_spec.fnl b/fnl/conjure-spec/remote/transport/base64_spec.fnl new file mode 100644 index 00000000..0378dafc --- /dev/null +++ b/fnl/conjure-spec/remote/transport/base64_spec.fnl @@ -0,0 +1,17 @@ +(local {: describe : it} (require :plenary.busted)) +(local assert (require :luassert.assert)) +(local b64 (require :conjure.remote.transport.base64)) + +(describe "conjure.remote.transport.base64" + (fn [] + (describe "basic" + (fn [] + (it "empty to empty" + (fn [] + (assert.are.equals "" (b64.encode "")))) + (it "simple text to base64" + (fn [] + (assert.are.equals "SGVsbG8sIFdvcmxkIQ==" (b64.encode "Hello, World!")))) + (it "base64 back to text" + (fn [] + (assert.are.equals "Hello, World!" (b64.decode "SGVsbG8sIFdvcmxkIQ==")))))))) diff --git a/fnl/conjure/remote/transport/base64.fnl b/fnl/conjure/remote/transport/base64.fnl index 774edcea..674bdba3 100644 --- a/fnl/conjure/remote/transport/base64.fnl +++ b/fnl/conjure/remote/transport/base64.fnl @@ -1,13 +1,9 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) - -(module conjure.remote.transport.base64) - ;; From https://stackoverflow.com/a/35303321/455137 ;; Converted to Fennel by antifennel. (local b "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") -(defn encode [data] +(fn encode [data] (.. (: (.. (data:gsub "." (fn [x] (var (r b) (values "" (x:byte))) @@ -34,7 +30,7 @@ (b:sub (+ c 1) (+ c 1)))) (. ["" "==" "="] (+ (% (length data) 3) 1)))) -(defn decode [data] +(fn decode [data] (set-forcibly! data (string.gsub data (.. "[^" b "=]") "")) (: (data:gsub "." (fn [x] @@ -61,4 +57,5 @@ 0)))) (string.char c)))) -*module* +{: encode + : decode} diff --git a/lua/conjure-spec/remote/transport/base64_spec.lua b/lua/conjure-spec/remote/transport/base64_spec.lua new file mode 100644 index 00000000..6bf18dd8 --- /dev/null +++ b/lua/conjure-spec/remote/transport/base64_spec.lua @@ -0,0 +1,24 @@ +-- [nfnl] Compiled from fnl/conjure-spec/remote/transport/base64_spec.fnl by https://github.com/Olical/nfnl, do not edit. +local _local_1_ = require("plenary.busted") +local describe = _local_1_["describe"] +local it = _local_1_["it"] +local assert = require("luassert.assert") +local b64 = require("conjure.remote.transport.base64") +local function _2_() + local function _3_() + local function _4_() + return assert.are.equals("", b64.encode("")) + end + it("empty to empty", _4_) + local function _5_() + return assert.are.equals("SGVsbG8sIFdvcmxkIQ==", b64.encode("Hello, World!")) + end + it("simple text to base64", _5_) + local function _6_() + return assert.are.equals("Hello, World!", b64.decode("SGVsbG8sIFdvcmxkIQ==")) + end + return it("base64 back to text", _6_) + end + return describe("basic", _3_) +end +return describe("conjure.remote.transport.base64", _2_) diff --git a/lua/conjure/remote/transport/base64.lua b/lua/conjure/remote/transport/base64.lua index a65ec8f2..65465c13 100644 --- a/lua/conjure/remote/transport/base64.lua +++ b/lua/conjure/remote/transport/base64.lua @@ -1,16 +1,4 @@ -- [nfnl] Compiled from fnl/conjure/remote/transport/base64.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.remote.transport.base64" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -do local _ = {nil, nil, nil} end local b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" local function encode(data) local function _1_(x) @@ -31,10 +19,8 @@ local function encode(data) end return b:sub((c + 1), (c + 1)) end - return (((data:gsub(".", _1_) .. "0000")):gsub("%d%d%d?%d?%d?%d?", _2_) .. ({"", "==", "="})[((#data % 3) + 1)]) + return ((data:gsub(".", _1_) .. "0000"):gsub("%d%d%d?%d?%d?%d?", _2_) .. ({"", "==", "="})[((#data % 3) + 1)]) end -_2amodule_2a["encode"] = encode -do local _ = {encode, nil} end local function decode(data) data = string.gsub(data, ("[^" .. b .. "=]"), "") local function _4_(x) @@ -61,6 +47,4 @@ local function decode(data) end return data:gsub(".", _4_):gsub("%d%d%d?%d?%d?%d?%d?%d?", _6_) end -_2amodule_2a["decode"] = decode -do local _ = {decode, nil} end -return _2amodule_2a +return {encode = encode, decode = decode} From 87d75758f489aaa89b97391bc764b77e204bac0b Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Tue, 27 Aug 2024 20:32:38 -1000 Subject: [PATCH 11/13] Convert remote/transport/bencode --- .../remote/transport/bencode_spec.fnl | 68 ++++++++++++++++++ fnl/conjure/remote/transport/bencode/init.fnl | 18 ++--- .../remote/transport/bencode_spec.lua | 72 +++++++++++++++++++ lua/conjure/remote/transport/bencode/init.lua | 28 ++------ 4 files changed, 154 insertions(+), 32 deletions(-) create mode 100644 fnl/conjure-spec/remote/transport/bencode_spec.fnl create mode 100644 lua/conjure-spec/remote/transport/bencode_spec.lua diff --git a/fnl/conjure-spec/remote/transport/bencode_spec.fnl b/fnl/conjure-spec/remote/transport/bencode_spec.fnl new file mode 100644 index 00000000..e71a42cf --- /dev/null +++ b/fnl/conjure-spec/remote/transport/bencode_spec.fnl @@ -0,0 +1,68 @@ +(local {: describe : it} (require :plenary.busted)) +(local assert (require :luassert.assert)) +(local a (require :nfnl.core)) +(local bencode (require :conjure.remote.transport.bencode)) + +(describe "conjure.remote.transport.bencode" + (fn [] + (describe "basic" + (fn [] + (let [bs (bencode.new) + data {:foo [:bar]}] + (it "data starts empty" + (fn [] + (assert.are.equals bs.data ""))) + (it "a single bencoded value" + (fn [] + (assert.same [data] (bencode.decode-all bs (bencode.encode data))))) + (it "data is empty after a decode" + (fn [] + (assert.are.equals bs.data "")))))) + + (describe "multiple-values" + (fn [] + (let [bs (bencode.new) + data-a {:foo [:bar]} + data-b [1 2 3]] + (it "data starts empty" + (fn [] + (assert.are.equals bs.data ""))) + (it "two bencoded values" + (fn [] + (assert.same [data-a data-b] + (bencode.decode-all + bs + (.. (bencode.encode data-a) + (bencode.encode data-b)))))) + (it "data is empty after a decode" + (fn [] + (assert.are.equals bs.data "")))))) + + (describe "partial-values" + (fn [] + (let [bs (bencode.new) + data-a {:foo [:bar]} + data-b [1 2 3] + encoded-b (bencode.encode data-b)] + (it "data starts empty" + (fn [] + (assert.are.equals bs.data ""))) + (it "first value" + (fn [] + (assert.same [data-a] + (bencode.decode-all + bs + (.. (bencode.encode data-a) + (string.sub encoded-b 1 3)))))) + (it "after first, data contains partial data-b" + (fn [] + (assert.are.equals "li1" bs.data))) + (it "second value after rest of data" + (fn [] + (assert.same [data-b] + (bencode.decode-all + bs + (string.sub encoded-b 4))))) + (it "data is empty after a decode" + (fn [] + (assert.are.equals bs.data "")))))))) diff --git a/fnl/conjure/remote/transport/bencode/init.fnl b/fnl/conjure/remote/transport/bencode/init.fnl index f38aac94..80e5cb27 100644 --- a/fnl/conjure/remote/transport/bencode/init.fnl +++ b/fnl/conjure/remote/transport/bencode/init.fnl @@ -1,13 +1,11 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) +(local {: autoload} (require :nfnl.module)) +(local impl (autoload :conjure.remote.transport.bencode.impl)) +(local a (autoload :conjure.aniseed.core)) -(module conjure.remote.transport.bencode - {autoload {impl conjure.remote.transport.bencode.impl - a conjure.aniseed.core}}) - -(defn new [] +(fn new [] {:data ""}) -(defn decode-all [bs part] +(fn decode-all [bs part] (var progress 1) (var end? false) (let [s (.. bs.data part) @@ -22,7 +20,9 @@ (a.assoc bs :data (string.sub s progress)) acc)) -(defn encode [...] +(fn encode [...] (impl.encode ...)) -*module* +{: new + : decode-all + : encode} diff --git a/lua/conjure-spec/remote/transport/bencode_spec.lua b/lua/conjure-spec/remote/transport/bencode_spec.lua new file mode 100644 index 00000000..eb288575 --- /dev/null +++ b/lua/conjure-spec/remote/transport/bencode_spec.lua @@ -0,0 +1,72 @@ +-- [nfnl] Compiled from fnl/conjure-spec/remote/transport/bencode_spec.fnl by https://github.com/Olical/nfnl, do not edit. +local _local_1_ = require("plenary.busted") +local describe = _local_1_["describe"] +local it = _local_1_["it"] +local assert = require("luassert.assert") +local a = require("nfnl.core") +local bencode = require("conjure.remote.transport.bencode") +local function _2_() + local function _3_() + local bs = bencode.new() + local data = {foo = {"bar"}} + local function _4_() + return assert.are.equals(bs.data, "") + end + it("data starts empty", _4_) + local function _5_() + return assert.same({data}, bencode["decode-all"](bs, bencode.encode(data))) + end + it("a single bencoded value", _5_) + local function _6_() + return assert.are.equals(bs.data, "") + end + return it("data is empty after a decode", _6_) + end + describe("basic", _3_) + local function _7_() + local bs = bencode.new() + local data_a = {foo = {"bar"}} + local data_b = {1, 2, 3} + local function _8_() + return assert.are.equals(bs.data, "") + end + it("data starts empty", _8_) + local function _9_() + return assert.same({data_a, data_b}, bencode["decode-all"](bs, (bencode.encode(data_a) .. bencode.encode(data_b)))) + end + it("two bencoded values", _9_) + local function _10_() + return assert.are.equals(bs.data, "") + end + return it("data is empty after a decode", _10_) + end + describe("multiple-values", _7_) + local function _11_() + local bs = bencode.new() + local data_a = {foo = {"bar"}} + local data_b = {1, 2, 3} + local encoded_b = bencode.encode(data_b) + local function _12_() + return assert.are.equals(bs.data, "") + end + it("data starts empty", _12_) + local function _13_() + return assert.same({data_a}, bencode["decode-all"](bs, (bencode.encode(data_a) .. string.sub(encoded_b, 1, 3)))) + end + it("first value", _13_) + local function _14_() + return assert.are.equals("li1", bs.data) + end + it("after first, data contains partial data-b", _14_) + local function _15_() + return assert.same({data_b}, bencode["decode-all"](bs, string.sub(encoded_b, 4))) + end + it("second value after rest of data", _15_) + local function _16_() + return assert.are.equals(bs.data, "") + end + return it("data is empty after a decode", _16_) + end + return describe("partial-values", _11_) +end +return describe("conjure.remote.transport.bencode", _2_) diff --git a/lua/conjure/remote/transport/bencode/init.lua b/lua/conjure/remote/transport/bencode/init.lua index cf816267..4ca33e26 100644 --- a/lua/conjure/remote/transport/bencode/init.lua +++ b/lua/conjure/remote/transport/bencode/init.lua @@ -1,25 +1,11 @@ -- [nfnl] Compiled from fnl/conjure/remote/transport/bencode/init.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.remote.transport.bencode" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, impl = autoload("conjure.aniseed.core"), autoload("conjure.remote.transport.bencode.impl") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["impl"] = impl -do local _ = {nil, nil, nil, nil, nil, nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local impl = autoload("conjure.remote.transport.bencode.impl") +local a = autoload("conjure.aniseed.core") local function new() return {data = ""} end -_2amodule_2a["new"] = new -do local _ = {new, nil} end local function decode_all(bs, part) local progress = 1 local end_3f = false @@ -37,11 +23,7 @@ local function decode_all(bs, part) a.assoc(bs, "data", string.sub(s, progress)) return acc end -_2amodule_2a["decode-all"] = decode_all -do local _ = {decode_all, nil} end local function encode(...) return impl.encode(...) end -_2amodule_2a["encode"] = encode -do local _ = {encode, nil} end -return _2amodule_2a +return {new = new, ["decode-all"] = decode_all, encode = encode} From a29f0e0c0ae5abb7e442c28627b09e0fda8cb75e Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Tue, 27 Aug 2024 21:37:11 -1000 Subject: [PATCH 12/13] Convert remote/stdio and associated test --- dev/python/sandbox.py | 2 ++ dev/sql/pg-docker.sh | 2 +- fnl/conjure-spec/remote/stdio_spec.fnl | 21 +++++++++++ fnl/conjure/remote/stdio-rt.fnl | 9 ++--- fnl/conjure/remote/stdio.fnl | 28 +++++++-------- lua/conjure-spec/remote/stdio_spec.lua | 29 ++++++++++++++++ lua/conjure/remote/stdio-rt.lua | 3 +- lua/conjure/remote/stdio.lua | 48 +++++++------------------- 8 files changed, 82 insertions(+), 60 deletions(-) create mode 100644 fnl/conjure-spec/remote/stdio_spec.fnl create mode 100644 lua/conjure-spec/remote/stdio_spec.lua diff --git a/dev/python/sandbox.py b/dev/python/sandbox.py index 6af6315e..ebcb2230 100644 --- a/dev/python/sandbox.py +++ b/dev/python/sandbox.py @@ -50,6 +50,7 @@ def fn_with_multiline_str(): fn_with_multiline_str() +""" async def slow_fn(): return "slow_fn result, this is async!" @@ -66,6 +67,7 @@ async def capture(): await capture() result +""" import csv diff --git a/dev/sql/pg-docker.sh b/dev/sql/pg-docker.sh index 3e67d0e4..95edf073 100755 --- a/dev/sql/pg-docker.sh +++ b/dev/sql/pg-docker.sh @@ -7,4 +7,4 @@ docker run \ -e POSTGRES_USER=postgres \ -e POSTGRES_PASSWORD=postgres \ -e POSTGRES_DB=postgres \ - postgres + postgres:13 diff --git a/fnl/conjure-spec/remote/stdio_spec.fnl b/fnl/conjure-spec/remote/stdio_spec.fnl new file mode 100644 index 00000000..0d5da5c3 --- /dev/null +++ b/fnl/conjure-spec/remote/stdio_spec.fnl @@ -0,0 +1,21 @@ +(local {: describe : it} (require :plenary.busted)) +(local assert (require :luassert.assert)) +(local a (require :nfnl.core)) +(local stdio (require :conjure.remote.stdio)) + +(describe "conjure.remote.stdio" + (fn [] + (describe "parse-cmd" + (fn [] + (it "parses a string" + (fn [] + (assert.same {:cmd "foo" :args []} (stdio.parse-cmd "foo")))) + (it "parses a list of one string" + (fn [] + (assert.same {:cmd "foo" :args []} (stdio.parse-cmd ["foo"])))) + (it "parses a string with words separated by spaces" + (fn [] + (assert.same {:cmd "foo" :args ["bar" "baz"]} (stdio.parse-cmd "foo bar baz")))) + (it "parses a list of more than one string" + (fn [] + (assert.same {:cmd "foo" :args ["bar" "baz"]} (stdio.parse-cmd ["foo" "bar" "baz"])))))))) diff --git a/fnl/conjure/remote/stdio-rt.fnl b/fnl/conjure/remote/stdio-rt.fnl index c8fc168d..137d889c 100644 --- a/fnl/conjure/remote/stdio-rt.fnl +++ b/fnl/conjure/remote/stdio-rt.fnl @@ -1,6 +1,5 @@ (local {: autoload} (require :nfnl.module)) (local a (autoload :conjure.aniseed.core)) -(local nvim (autoload :conjure.aniseed.nvim)) (local str (autoload :conjure.aniseed.string)) (local client (autoload :conjure.client)) (local log (autoload :conjure.log)) @@ -23,7 +22,7 @@ (fn extend-env [vars] (->> (a.merge - (nvim.fn.environ) + (vim.fn.environ) vars) (a.kv-pairs) (a.map @@ -152,7 +151,5 @@ (client.schedule #(opts.on-error pid-or-err)) (destroy)))))) -{ - : parse-cmd - : start - } +{: parse-cmd + : start} diff --git a/fnl/conjure/remote/stdio.fnl b/fnl/conjure/remote/stdio.fnl index 2c4a5cd2..7406ef07 100644 --- a/fnl/conjure/remote/stdio.fnl +++ b/fnl/conjure/remote/stdio.fnl @@ -1,20 +1,17 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local str (autoload :conjure.aniseed.string)) +(local client (autoload :conjure.client)) +(local log (autoload :conjure.log)) -(module conjure.remote.stdio - {autoload {a conjure.aniseed.core - nvim conjure.aniseed.nvim - str conjure.aniseed.string - client conjure.client - log conjure.log}}) +(local uv vim.loop) -(def- uv vim.loop) - -(defn- parse-prompt [s pat] +(fn parse-prompt [s pat] (if (s:find pat) (values true (s:gsub pat "")) (values false s))) -(defn parse-cmd [x] +(fn parse-cmd [x] (if (a.table? x) {:cmd (a.first x) @@ -23,16 +20,16 @@ (a.string? x) (parse-cmd (str.split x "%s")))) -(defn- extend-env [vars] +(fn extend-env [vars] (->> (a.merge - (nvim.fn.environ) + (vim.fn.environ) vars) (a.kv-pairs) (a.map (fn [[k v]] (.. k "=" v))))) -(defn start [opts] +(fn start [opts] "Starts an external REPL and gives you hooks to send code to it and read responses back out. Tying an input to a result is near enough impossible through this stdio medium, so it's a best effort. @@ -149,4 +146,5 @@ (client.schedule #(opts.on-error pid-or-err)) (destroy)))))) -*module* +{: parse-cmd + : start} diff --git a/lua/conjure-spec/remote/stdio_spec.lua b/lua/conjure-spec/remote/stdio_spec.lua new file mode 100644 index 00000000..29808a30 --- /dev/null +++ b/lua/conjure-spec/remote/stdio_spec.lua @@ -0,0 +1,29 @@ +-- [nfnl] Compiled from fnl/conjure-spec/remote/stdio_spec.fnl by https://github.com/Olical/nfnl, do not edit. +local _local_1_ = require("plenary.busted") +local describe = _local_1_["describe"] +local it = _local_1_["it"] +local assert = require("luassert.assert") +local a = require("nfnl.core") +local stdio = require("conjure.remote.stdio") +local function _2_() + local function _3_() + local function _4_() + return assert.same({cmd = "foo", args = {}}, stdio["parse-cmd"]("foo")) + end + it("parses a string", _4_) + local function _5_() + return assert.same({cmd = "foo", args = {}}, stdio["parse-cmd"]({"foo"})) + end + it("parses a list of one string", _5_) + local function _6_() + return assert.same({cmd = "foo", args = {"bar", "baz"}}, stdio["parse-cmd"]("foo bar baz")) + end + it("parses a string with words separated by spaces", _6_) + local function _7_() + return assert.same({cmd = "foo", args = {"bar", "baz"}}, stdio["parse-cmd"]({"foo", "bar", "baz"})) + end + return it("parses a list of more than one string", _7_) + end + return describe("parse-cmd", _3_) +end +return describe("conjure.remote.stdio", _2_) diff --git a/lua/conjure/remote/stdio-rt.lua b/lua/conjure/remote/stdio-rt.lua index b2fd2c55..7417be2f 100644 --- a/lua/conjure/remote/stdio-rt.lua +++ b/lua/conjure/remote/stdio-rt.lua @@ -2,7 +2,6 @@ local _local_1_ = require("nfnl.module") local autoload = _local_1_["autoload"] local a = autoload("conjure.aniseed.core") -local nvim = autoload("conjure.aniseed.nvim") local str = autoload("conjure.aniseed.string") local client = autoload("conjure.client") local log = autoload("conjure.log") @@ -29,7 +28,7 @@ local function extend_env(vars) local v = _4_[2] return (k .. "=" .. v) end - return a.map(_5_, a["kv-pairs"](a.merge(nvim.fn.environ(), vars))) + return a.map(_5_, a["kv-pairs"](a.merge(vim.fn.environ(), vars))) end local function start(opts) local stdin = uv.new_pipe(false) diff --git a/lua/conjure/remote/stdio.lua b/lua/conjure/remote/stdio.lua index 7873eac0..8bba612f 100644 --- a/lua/conjure/remote/stdio.lua +++ b/lua/conjure/remote/stdio.lua @@ -1,26 +1,11 @@ -- [nfnl] Compiled from fnl/conjure/remote/stdio.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.remote.stdio" -local _2amodule_2a -do - _G.package.loaded[_2amodule_name_2a] = {} - _2amodule_2a = _G.package.loaded[_2amodule_name_2a] -end -local _2amodule_locals_2a -do - _2amodule_2a["aniseed/locals"] = {} - _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] -end -local autoload = (require("aniseed.autoload")).autoload -local a, client, log, nvim, str = autoload("conjure.aniseed.core"), autoload("conjure.client"), autoload("conjure.log"), autoload("conjure.aniseed.nvim"), autoload("conjure.aniseed.string") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["client"] = client -_2amodule_locals_2a["log"] = log -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["str"] = str -do local _ = {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil} end +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local str = autoload("conjure.aniseed.string") +local client = autoload("conjure.client") +local log = autoload("conjure.log") local uv = vim.loop -_2amodule_locals_2a["uv"] = uv -do local _ = {nil, nil} end local function parse_prompt(s, pat) if s:find(pat) then return true, s:gsub(pat, "") @@ -28,8 +13,6 @@ local function parse_prompt(s, pat) return false, s end end -_2amodule_locals_2a["parse-prompt"] = parse_prompt -do local _ = {parse_prompt, nil} end local function parse_cmd(x) if a["table?"](x) then return {cmd = a.first(x), args = a.rest(x)} @@ -39,19 +22,14 @@ local function parse_cmd(x) return nil end end -_2amodule_2a["parse-cmd"] = parse_cmd -do local _ = {parse_cmd, nil} end local function extend_env(vars) - local function _5_(_3_) - local _arg_4_ = _3_ - local k = _arg_4_[1] - local v = _arg_4_[2] + local function _5_(_4_) + local k = _4_[1] + local v = _4_[2] return (k .. "=" .. v) end - return a.map(_5_, a["kv-pairs"](a.merge(nvim.fn.environ(), vars))) + return a.map(_5_, a["kv-pairs"](a.merge(vim.fn.environ(), vars))) end -_2amodule_locals_2a["extend-env"] = extend_env -do local _ = {extend_env, nil} end local function start(opts) local stdin = uv.new_pipe(false) local stdout = uv.new_pipe(false) @@ -84,7 +62,7 @@ local function start(opts) end pcall(_11_) local function _12_() - return (repl.handle):close() + return repl.handle:close() end pcall(_12_) else @@ -190,6 +168,4 @@ local function start(opts) return destroy() end end -_2amodule_2a["start"] = start -do local _ = {start, nil} end -return _2amodule_2a +return {["parse-cmd"] = parse_cmd, start = start} From 098aba0532aef5f8e31537e64e055e8793c8f9fb Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Tue, 27 Aug 2024 21:43:57 -1000 Subject: [PATCH 13/13] Revert dev/sql/pg-docker.sh --- dev/sql/pg-docker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/sql/pg-docker.sh b/dev/sql/pg-docker.sh index 95edf073..3e67d0e4 100755 --- a/dev/sql/pg-docker.sh +++ b/dev/sql/pg-docker.sh @@ -7,4 +7,4 @@ docker run \ -e POSTGRES_USER=postgres \ -e POSTGRES_PASSWORD=postgres \ -e POSTGRES_DB=postgres \ - postgres:13 + postgres