From 339cca764b29d300b1a35f9c72d7a0b2406e7d23 Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Sat, 31 Aug 2024 07:36:08 -1000 Subject: [PATCH 1/8] Convert remote/stdio2 --- fnl/conjure-spec/remote/stdio2_spec.fnl | 20 ++++++++++++++++ fnl/conjure-spec/remote/stdio_spec.fnl | 1 - fnl/conjure/remote/stdio2.fnl | 19 +++++++-------- lua/conjure-spec/remote/stdio2_spec.lua | 28 ++++++++++++++++++++++ lua/conjure-spec/remote/stdio_spec.lua | 1 - lua/conjure/remote/stdio2.lua | 31 ++++++------------------- 6 files changed, 63 insertions(+), 37 deletions(-) create mode 100644 fnl/conjure-spec/remote/stdio2_spec.fnl create mode 100644 lua/conjure-spec/remote/stdio2_spec.lua diff --git a/fnl/conjure-spec/remote/stdio2_spec.fnl b/fnl/conjure-spec/remote/stdio2_spec.fnl new file mode 100644 index 00000000..12071bd3 --- /dev/null +++ b/fnl/conjure-spec/remote/stdio2_spec.fnl @@ -0,0 +1,20 @@ +(local {: describe : it} (require :plenary.busted)) +(local assert (require :luassert.assert)) +(local stdio (require :conjure.remote.stdio2)) + +(describe "conjure.remote.stdio2" + (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-spec/remote/stdio_spec.fnl b/fnl/conjure-spec/remote/stdio_spec.fnl index 0d5da5c3..30b07102 100644 --- a/fnl/conjure-spec/remote/stdio_spec.fnl +++ b/fnl/conjure-spec/remote/stdio_spec.fnl @@ -1,6 +1,5 @@ (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" diff --git a/fnl/conjure/remote/stdio2.fnl b/fnl/conjure/remote/stdio2.fnl index 96bbcb06..7897c06b 100644 --- a/fnl/conjure/remote/stdio2.fnl +++ b/fnl/conjure/remote/stdio2.fnl @@ -1,15 +1,12 @@ -(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.stdio2 - {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-cmd [x] +(fn parse-cmd [x] (if (a.table? x) {:cmd (a.first x) @@ -18,4 +15,4 @@ (a.string? x) (parse-cmd (str.split x "%s")))) -*module* +{: parse-cmd} diff --git a/lua/conjure-spec/remote/stdio2_spec.lua b/lua/conjure-spec/remote/stdio2_spec.lua new file mode 100644 index 00000000..dae8ad00 --- /dev/null +++ b/lua/conjure-spec/remote/stdio2_spec.lua @@ -0,0 +1,28 @@ +-- [nfnl] Compiled from fnl/conjure-spec/remote/stdio2_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 stdio = require("conjure.remote.stdio2") +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.stdio2", _2_) diff --git a/lua/conjure-spec/remote/stdio_spec.lua b/lua/conjure-spec/remote/stdio_spec.lua index 29808a30..2cfad03a 100644 --- a/lua/conjure-spec/remote/stdio_spec.lua +++ b/lua/conjure-spec/remote/stdio_spec.lua @@ -3,7 +3,6 @@ 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_() diff --git a/lua/conjure/remote/stdio2.lua b/lua/conjure/remote/stdio2.lua index dfb4061f..58dfac15 100644 --- a/lua/conjure/remote/stdio2.lua +++ b/lua/conjure/remote/stdio2.lua @@ -1,26 +1,11 @@ -- [nfnl] Compiled from fnl/conjure/remote/stdio2.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.remote.stdio2" -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_cmd(x) if a["table?"](x) then return {cmd = a.first(x), args = a.rest(x)} @@ -30,6 +15,4 @@ local function parse_cmd(x) return nil end end -_2amodule_2a["parse-cmd"] = parse_cmd -do local _ = {parse_cmd, nil} end -return _2amodule_2a +return {["parse-cmd"] = parse_cmd} From 259cd2daf1a2290be674a90d055e2f10318c193f Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Sat, 31 Aug 2024 09:08:36 -1000 Subject: [PATCH 2/8] Convert Common Lisp client. Touch up Racket client. --- fnl/conjure/client/common-lisp/swank.fnl | 97 +++++++------ fnl/conjure/client/racket/stdio.fnl | 2 +- fnl/conjure/remote/swank.fnl | 25 ++-- fnl/conjure/remote/transport/swank.fnl | 14 +- lua/conjure/client/common-lisp/swank.lua | 171 +++++++---------------- lua/conjure/client/racket/stdio.lua | 2 +- lua/conjure/remote/swank.lua | 45 ++---- lua/conjure/remote/transport/swank.lua | 26 +--- 8 files changed, 143 insertions(+), 239 deletions(-) diff --git a/fnl/conjure/client/common-lisp/swank.fnl b/fnl/conjure/client/common-lisp/swank.fnl index 31b7fe3f..d9711fcc 100644 --- a/fnl/conjure/client/common-lisp/swank.fnl +++ b/fnl/conjure/client/common-lisp/swank.fnl @@ -1,31 +1,27 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) - -(module conjure.client.common-lisp.swank - {autoload {a conjure.aniseed.core - nvim conjure.aniseed.nvim - bridge conjure.bridge - mapping conjure.mapping - text conjure.text - log conjure.log - str conjure.aniseed.string - config conjure.config - client conjure.client - remote conjure.remote.swank - util conjure.util - ts conjure.tree-sitter}}) - -(def buf-suffix ".lisp") -(def comment-prefix "; ") -(def form-node? ts.node-surrounded-by-form-pair-chars?) - -(defn- iterate-backwards [f lines] +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local client (autoload :conjure.client)) +(local config (autoload :conjure.config)) +(local log (autoload :conjure.log)) +(local mapping (autoload :conjure.mapping)) +(local remote (autoload :conjure.remote.swank)) +(local str (autoload :conjure.aniseed.string)) +(local text (autoload :conjure.text)) +(local ts (autoload :conjure.tree-sitter)) +(local util (autoload :conjure.util)) + +(local buf-suffix ".lisp") +(local comment-prefix "; ") +(local form-node? ts.node-surrounded-by-form-pair-chars?) + +(fn iterate-backwards [f lines] (for [i (length lines) 1 (- 1)] (local line (. lines i)) (let [res (f line)] (when res (lua "return res")))) nil) -(defn context [_code] +(fn context [_code] (let [[line _col] (vim.api.nvim_win_get_cursor 0) lines (vim.api.nvim_buf_get_lines 0 0 line false)] (iterate-backwards @@ -55,37 +51,37 @@ {:mapping {:connect "cc" :disconnect "cd"}}}}})) -(defonce- state (client.new-state +(local state (client.new-state #(do {:conn nil :eval-id 0}))) -(defn- with-conn-or-warn [f opts] +(fn with-conn-or-warn [f opts] (let [conn (state :conn)] (if conn (f conn) (log.append "; No connection")))) -(defn- connected? [] +(fn connected? [] (if (state :conn) true false)) -(defn- display-conn-status [status] +(fn display-conn-status [status] (with-conn-or-warn (fn [conn] (log.append [(.. "; " conn.host ":" conn.port " (" status ")")] {:break? true})))) -(defn disconnect [] +(fn disconnect [] (with-conn-or-warn (fn [conn] (conn.destroy) (display-conn-status :disconnected) (a.assoc (state) :conn nil)))) -(defn- escape-string [in] +(fn escape-string [in] "puts leading slashes infront of \\ and \" so that swank can correctly interpret the results." (fn replace [in pat rep] @@ -94,7 +90,7 @@ (replace "\\" "\\\\") (replace "\"" "\\\""))) -(defn- send [msg context cb] +(fn send [msg context cb] (log.dbg (.. "swank.send called with msg: " (a.pr-str msg) ", context: " (a.pr-str context))) (with-conn-or-warn (fn [conn] @@ -110,7 +106,7 @@ "\") \"" (or context "*package*") "\" t " eval-id ")"]) cb))))) -(defn connect [opts] +(fn connect [opts] (log.dbg (.. "connect called with: " (a.pr-str opts))) (let [opts (or opts {}) host (or opts.host (config.get-in [:client :common_lisp :swank :connection :default_host])) @@ -142,11 +138,11 @@ (send ":ok" (fn [_])))) -(defn- try-ensure-conn [] +(fn try-ensure-conn [] (when (not (connected?)) (connect {:silent? true}))) -(defn- string-stream [str] +(fn string-stream [str] "Convert a string into a byte-value iterator" (var index 1) (fn [] @@ -154,12 +150,12 @@ (set index (+ index 1)) r))) -(defn- display-stdout [msg] +(fn display-stdout [msg] (when (and (not= nil msg) (not= "" msg)) (log.append (text.prefixed-lines msg comment-prefix)))) -(defn- inner-results [received] +(fn inner-results [received] "A string of '(:return (:ok (blah)) 1)' should just give us the blah" ;; this is super hacky, but it seems to work, so we're going with it ;; until something better comes along. @@ -170,7 +166,7 @@ (+ idx len) (- (string.len received) tail-size)))) -(defn- parse-separated-list [string-to-parse] +(fn parse-separated-list [string-to-parse] "Take a string of quoted components and return an array of those values, ie: (I'm using single instead of double quotes in the example for ease) @@ -236,7 +232,7 @@ ;;finally return vals vals) -(defn parse-result [received] +(fn parse-result [received] "Given the form (:return (:ok (\"\" \"(1 2 \\\"3\\\" 4)\")) 1) we want)]) to extract both - the stdout, which is the first delimited quoted component @@ -258,7 +254,7 @@ (when (result? received) (unpack (parse-separated-list (inner-results received))))) -(defn eval-str [opts] +(fn eval-str [opts] (log.dbg (.. "eval-str() called with: " (a.pr-str opts))) (try-ensure-conn) @@ -277,16 +273,16 @@ (when (not opts.passive?) ;; log results when not true (log.append (text.split-lines result))))))))) -(defn doc-str [opts] +(fn doc-str [opts] (try-ensure-conn) (eval-str (a.update opts :code #(.. "(describe '" $1 ")")))) -(defn eval-file [opts] +(fn eval-file [opts] (try-ensure-conn) (eval-str (a.assoc opts :code (.. "(load \"" opts.file-path "\")")))) -(defn on-filetype [] +(fn on-filetype [] (mapping.buf :CommonLispDisconnect (config.get-in [:client :common_lisp :swank :mapping :disconnect]) @@ -299,14 +295,14 @@ #(connect {}) {:desc "Connect to a REPL"})) -(defn on-load [] +(fn on-load [] (connect {})) -(defn on-exit [] +(fn on-exit [] (disconnect)) ;; completions - partially copied from client/fennel/aniseed.fnl. -(defn completions [opts] +(fn completions [opts] ;(when (not= nil opts) ; (log.append [(.. "; completions() called with: " (a.pr-str opts))] {:break? true})) (try-ensure-conn) @@ -330,4 +326,17 @@ (a.assoc opts :passive? true) (eval-str opts))) -*module* +{: buf-suffix + : comment-prefix + : form-node? + : context + : disconnect + : connect + : parse-result + : eval-str + : doc-str + : eval-file + : on-filetype + : on-load + : on-exit + : completions} diff --git a/fnl/conjure/client/racket/stdio.fnl b/fnl/conjure/client/racket/stdio.fnl index 1c32cd1e..192ae10e 100644 --- a/fnl/conjure/client/racket/stdio.fnl +++ b/fnl/conjure/client/racket/stdio.fnl @@ -102,7 +102,7 @@ (fn enter [] (let [repl (state :repl) - path (nvim.fn.expand "%:p")] + path (vim.fn.expand "%:p")] (when (and repl (not (log.log-buf? path))) (repl.send (prep-code (.. ",enter " path)) diff --git a/fnl/conjure/remote/swank.fnl b/fnl/conjure/remote/swank.fnl index 86da06cd..4df05ece 100644 --- a/fnl/conjure/remote/swank.fnl +++ b/fnl/conjure/remote/swank.fnl @@ -1,21 +1,18 @@ -(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) - -(module conjure.remote.swank - {autoload {a conjure.aniseed.core - net conjure.net - log conjure.log - client conjure.client - trn conjure.remote.transport.swank - nvim conjure.aniseed.nvim}}) - -(defn send [conn msg cb] +(local {: autoload} (require :nfnl.module)) +(local a (autoload :conjure.aniseed.core)) +(local client (autoload :conjure.client)) +(local log (autoload :conjure.log)) +(local net (autoload :conjure.net)) +(local trn (autoload :conjure.remote.transport.swank)) + +(fn send [conn msg cb] "Send a message to the given connection, call the callback when a response is received." ; (log.dbg "send" msg) (table.insert conn.queue 1 (or cb false)) (conn.sock:write (trn.encode msg)) nil) -(defn connect [opts] +(fn connect [opts] "Connects to a remote swank server. * opts.host: The host string. * opts.port: Port as a string. @@ -57,5 +54,5 @@ ; (send conn (or opts.name "Conjure")) conn) - -*module* +{: send + : connect} diff --git a/fnl/conjure/remote/transport/swank.fnl b/fnl/conjure/remote/transport/swank.fnl index 8357de47..1a177645 100644 --- a/fnl/conjure/remote/transport/swank.fnl +++ b/fnl/conjure/remote/transport/swank.fnl @@ -1,17 +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 log (autoload :conjure.log)) -(module conjure.remote.transport.swank - {autoload {a conjure.aniseed.core - log conjure.log}}) - -(defn encode [msg] +(fn encode [msg] (let [n (a.count msg) header (string.format "%06x" (+ 1 n))] ; Additional 1 for trailing newline (.. header msg "\n"))) -(defn decode [msg] +(fn decode [msg] (let [len (tonumber (string.sub msg 1 7) 16) cmd (string.sub msg 7 len)] cmd)) -*module* +{: encode : decode} diff --git a/lua/conjure/client/common-lisp/swank.lua b/lua/conjure/client/common-lisp/swank.lua index 520fb13b..c06c69cc 100644 --- a/lua/conjure/client/common-lisp/swank.lua +++ b/lua/conjure/client/common-lisp/swank.lua @@ -1,36 +1,19 @@ -- [nfnl] Compiled from fnl/conjure/client/common-lisp/swank.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.client.common-lisp.swank" -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("conjure.aniseed.autoload")).autoload -local a, bridge, client, config, log, mapping, nvim, remote, str, text, ts, util = autoload("conjure.aniseed.core"), autoload("conjure.bridge"), autoload("conjure.client"), autoload("conjure.config"), autoload("conjure.log"), autoload("conjure.mapping"), autoload("conjure.aniseed.nvim"), autoload("conjure.remote.swank"), autoload("conjure.aniseed.string"), autoload("conjure.text"), autoload("conjure.tree-sitter"), autoload("conjure.util") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["bridge"] = bridge -_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["remote"] = remote -_2amodule_locals_2a["str"] = str -_2amodule_locals_2a["text"] = text -_2amodule_locals_2a["ts"] = ts -_2amodule_locals_2a["util"] = util +local _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] +local a = autoload("conjure.aniseed.core") +local client = autoload("conjure.client") +local config = autoload("conjure.config") +local log = autoload("conjure.log") +local mapping = autoload("conjure.mapping") +local remote = autoload("conjure.remote.swank") +local str = autoload("conjure.aniseed.string") +local text = autoload("conjure.text") +local ts = autoload("conjure.tree-sitter") +local util = autoload("conjure.util") local buf_suffix = ".lisp" -_2amodule_2a["buf-suffix"] = buf_suffix 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 local function iterate_backwards(f, lines) for i = #lines, 1, ( - 1) do local line = lines[i] @@ -42,30 +25,26 @@ local function iterate_backwards(f, lines) end return nil end -_2amodule_locals_2a["iterate-backwards"] = iterate_backwards local function context(_code) - local _let_2_ = vim.api.nvim_win_get_cursor(0) - local line = _let_2_[1] - local _col = _let_2_[2] + local _let_3_ = vim.api.nvim_win_get_cursor(0) + local line = _let_3_[1] + local _col = _let_3_[2] local lines = vim.api.nvim_buf_get_lines(0, 0, line, false) - local function _3_(line0) + local function _4_(line0) return (string.match(line0, "%(%s*defpackage%s+(.-)[%s){]") or string.match(line0, "%(%s*in%-package%s+(.-)[%s){]")) end - return iterate_backwards(_3_, lines) + return iterate_backwards(_4_, lines) end -_2amodule_2a["context"] = context config.merge({client = {common_lisp = {swank = {connection = {default_host = "127.0.0.1", default_port = "4005"}}}}}) if config["get-in"]({"mapping", "enable_defaults"}) then config.merge({client = {common_lisp = {swank = {mapping = {connect = "cc", disconnect = "cd"}}}}}) else end local state -local function _5_() +local function _6_() return {conn = nil, ["eval-id"] = 0} end -state = ((_2amodule_2a).state or client["new-state"](_5_)) -do end (_2amodule_locals_2a)["state"] = state -do local _ = {nil, nil} end +state = client["new-state"](_6_) local function with_conn_or_warn(f, opts) local conn = state("conn") if conn then @@ -74,8 +53,6 @@ local function with_conn_or_warn(f, opts) return log.append("; No connection") end end -_2amodule_locals_2a["with-conn-or-warn"] = with_conn_or_warn -do local _ = {with_conn_or_warn, nil} end local function connected_3f() if state("conn") then return true @@ -83,26 +60,20 @@ local function connected_3f() return false end end -_2amodule_locals_2a["connected?"] = connected_3f -do local _ = {connected_3f, nil} end local function display_conn_status(status) - local function _8_(conn) + local function _9_(conn) return log.append({("; " .. conn.host .. ":" .. conn.port .. " (" .. status .. ")")}, {["break?"] = true}) end - return with_conn_or_warn(_8_) + return with_conn_or_warn(_9_) end -_2amodule_locals_2a["display-conn-status"] = display_conn_status -do local _ = {display_conn_status, nil} end local function disconnect() - local function _9_(conn) + local function _10_(conn) conn.destroy() display_conn_status("disconnected") return a.assoc(state(), "conn", nil) end - return with_conn_or_warn(_9_) + return with_conn_or_warn(_10_) end -_2amodule_2a["disconnect"] = disconnect -do local _ = {disconnect, nil} end local function escape_string(_in) local function replace(_in0, pat, rep) local s, c = string.gsub(_in0, pat, rep) @@ -110,17 +81,14 @@ local function escape_string(_in) end return replace(replace(_in, "\\", "\\\\"), "\"", "\\\"") end -_2amodule_locals_2a["escape-string"] = escape_string local function send(msg, context0, cb) log.dbg(("swank.send called with msg: " .. a["pr-str"](msg) .. ", context: " .. a["pr-str"](context0))) - local function _10_(conn) + local function _11_(conn) local eval_id = a.get(a.update(state(), "eval-id", a.inc), "eval-id") return remote.send(conn, str.join({"(:emacs-rex (swank:eval-and-grab-output \"", escape_string(msg), "\") \"", (context0 or "*package*"), "\" t ", eval_id, ")"}), cb) end - return with_conn_or_warn(_10_) + return with_conn_or_warn(_11_) end -_2amodule_locals_2a["send"] = send -do local _ = {send, nil} end local function connect(opts) log.dbg(("connect called with: " .. a["pr-str"](opts))) local opts0 = (opts or {}) @@ -130,27 +98,25 @@ local function connect(opts) disconnect() else end - local function _12_(err) + local function _13_(err) display_conn_status(err) return disconnect() end - local function _13_() + local function _14_() return display_conn_status("connected") end - local function _14_(err) + local function _15_(err) if err then return display_conn_status(err) else return disconnect() end end - a.assoc(state(), "conn", remote.connect({host = host, port = port, ["on-failure"] = _12_, ["on-success"] = _13_, ["on-error"] = _14_})) - local function _16_(_) + a.assoc(state(), "conn", remote.connect({host = host, port = port, ["on-failure"] = _13_, ["on-success"] = _14_, ["on-error"] = _15_})) + local function _17_(_) end - return send(":ok", _16_) + return send(":ok", _17_) end -_2amodule_2a["connect"] = connect -do local _ = {connect, nil} end local function try_ensure_conn() if not connected_3f() then return connect({["silent?"] = true}) @@ -158,19 +124,15 @@ local function try_ensure_conn() return nil end end -_2amodule_locals_2a["try-ensure-conn"] = try_ensure_conn -do local _ = {try_ensure_conn, nil} end local function string_stream(str0) local index = 1 - local function _18_() + local function _19_() local r = str0:byte(index) index = (index + 1) return r end - return _18_ + return _19_ end -_2amodule_locals_2a["string-stream"] = string_stream -do local _ = {string_stream, nil} end local function display_stdout(msg) if ((nil ~= msg) and ("" ~= msg)) then return log.append(text["prefixed-lines"](msg, comment_prefix)) @@ -178,16 +140,12 @@ local function display_stdout(msg) return nil end end -_2amodule_locals_2a["display-stdout"] = display_stdout -do local _ = {display_stdout, nil} end local function inner_results(received) local search_string = "(:return (:ok (" local tail_size = 5 local idx, len = string.find(received, search_string, 1, true) return string.sub(received, (idx + len), (string.len(received) - tail_size)) end -_2amodule_locals_2a["inner-results"] = inner_results -do local _ = {inner_results, nil} end local function parse_separated_list(string_to_parse) local opened_quote = nil local escaped = false @@ -235,16 +193,13 @@ local function parse_separated_list(string_to_parse) end end local function dispatch(b) - local _26_ = b - if (_26_ == slash_byte) then + if (b == slash_byte) then return slash_escape(b) - elseif (_26_ == quote_byte) then + elseif (b == quote_byte) then return maybe_close(b) - elseif true then - local _ = _26_ - return maybe_insert(b) else - return nil + local _ = b + return maybe_insert(b) end end for b in string_stream(string_to_parse) do @@ -252,18 +207,12 @@ local function parse_separated_list(string_to_parse) end return vals end -_2amodule_locals_2a["parse-separated-list"] = parse_separated_list -do local _ = {parse_separated_list, nil} end local function parse_result(received) local function result_3f(response) return text["starts-with"](response, "(:return (:ok (") end if not result_3f(received) then - local msg - do - local _28_ = parse_separated_list(received) - msg = _28_ - end + local msg = (parse_separated_list(received)) display_stdout(msg[1]) else end @@ -273,19 +222,17 @@ local function parse_result(received) return nil end end -_2amodule_2a["parse-result"] = parse_result -do local _ = {parse_result, nil} end local function eval_str(opts) log.dbg(("eval-str() called with: " .. a["pr-str"](opts))) try_ensure_conn() if not a["empty?"](opts.code) then - local _31_ + local _30_ if not a["empty?"](opts.context) then - _31_ = opts.context + _30_ = opts.context else - _31_ = nil + _30_ = nil end - local function _33_(msg) + local function _32_(msg) local stdout, result = parse_result(msg) display_stdout(stdout) if (nil ~= result) then @@ -302,69 +249,55 @@ local function eval_str(opts) return nil end end - return send(opts.code, _31_, _33_) + return send(opts.code, _30_, _32_) else return nil end end -_2amodule_2a["eval-str"] = eval_str -do local _ = {eval_str, nil} end local function doc_str(opts) try_ensure_conn() - local function _38_(_241) + local function _37_(_241) return ("(describe '" .. _241 .. ")") end - return eval_str(a.update(opts, "code", _38_)) + return eval_str(a.update(opts, "code", _37_)) end -_2amodule_2a["doc-str"] = doc_str -do local _ = {doc_str, nil} end local function eval_file(opts) try_ensure_conn() 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 on_filetype() mapping.buf("CommonLispDisconnect", config["get-in"]({"client", "common_lisp", "swank", "mapping", "disconnect"}), disconnect, {desc = "Disconnect from the REPL"}) - local function _39_() + local function _38_() return connect({}) end - return mapping.buf("CommonLispConnect", config["get-in"]({"client", "common_lisp", "swank", "mapping", "connect"}), _39_, {desc = "Connect to a REPL"}) + return mapping.buf("CommonLispConnect", config["get-in"]({"client", "common_lisp", "swank", "mapping", "connect"}), _38_, {desc = "Connect to a REPL"}) end -_2amodule_2a["on-filetype"] = on_filetype -do local _ = {on_filetype, nil} end local function on_load() return connect({}) end -_2amodule_2a["on-load"] = on_load -do local _ = {on_load, nil} end local function on_exit() return disconnect() end -_2amodule_2a["on-exit"] = on_exit -do local _ = {on_exit, nil} end local function completions(opts) try_ensure_conn() local code = ("(swank:simple-completions " .. a["pr-str"](opts.prefix) .. " " .. a["pr-str"](opts.context) .. ")") local format_for_cmpl - local function _40_(rs) + local function _39_(rs) local cmpls = parse_separated_list(rs) local last = table.remove(cmpls) table.insert(cmpls, 1, last) return cmpls end - format_for_cmpl = _40_ + format_for_cmpl = _39_ local result_fn - local function _41_(results) + local function _40_(results) local cmpl_list = format_for_cmpl(results) return opts.cb(cmpl_list) end - result_fn = _41_ + result_fn = _40_ a.assoc(opts, "code", code) a.assoc(opts, "on-result", result_fn) a.assoc(opts, "passive?", true) return eval_str(opts) end -_2amodule_2a["completions"] = completions -do local _ = {completions, nil} end -return _2amodule_2a +return {["buf-suffix"] = buf_suffix, ["comment-prefix"] = comment_prefix, ["form-node?"] = form_node_3f, context = context, disconnect = disconnect, connect = connect, ["parse-result"] = parse_result, ["eval-str"] = eval_str, ["doc-str"] = doc_str, ["eval-file"] = eval_file, ["on-filetype"] = on_filetype, ["on-load"] = on_load, ["on-exit"] = on_exit, completions = completions} diff --git a/lua/conjure/client/racket/stdio.lua b/lua/conjure/client/racket/stdio.lua index e28f1bec..a109a8a3 100644 --- a/lua/conjure/client/racket/stdio.lua +++ b/lua/conjure/client/racket/stdio.lua @@ -104,7 +104,7 @@ local function stop() end local function enter() local repl = state("repl") - local path = nvim.fn.expand("%:p") + local path = vim.fn.expand("%:p") if (repl and not log["log-buf?"](path)) then local function _14_() end diff --git a/lua/conjure/remote/swank.lua b/lua/conjure/remote/swank.lua index 7205152e..104c46c9 100644 --- a/lua/conjure/remote/swank.lua +++ b/lua/conjure/remote/swank.lua @@ -1,38 +1,23 @@ -- [nfnl] Compiled from fnl/conjure/remote/swank.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.remote.swank" -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, net, nvim, trn = autoload("conjure.aniseed.core"), autoload("conjure.client"), autoload("conjure.log"), autoload("conjure.net"), autoload("conjure.aniseed.nvim"), autoload("conjure.remote.transport.swank") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["client"] = client -_2amodule_locals_2a["log"] = log -_2amodule_locals_2a["net"] = net -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["trn"] = trn -do local _ = {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 client = autoload("conjure.client") +local log = autoload("conjure.log") +local net = autoload("conjure.net") +local trn = autoload("conjure.remote.transport.swank") local function send(conn, msg, cb) table.insert(conn.queue, 1, (cb or false)) - do end (conn.sock):write(trn.encode(msg)) + conn.sock:write(trn.encode(msg)) return nil end -_2amodule_2a["send"] = send -do local _ = {send, nil} end local function connect(opts) local conn = {decode = trn.decode, queue = {}} local function handle_message(err, chunk) if (err or not chunk) then return opts["on-error"](err) else - local function _1_(msg) + local function _2_(msg) local cb = table.remove(conn.queue) if cb then return cb(msg) @@ -40,20 +25,18 @@ local function connect(opts) return nil end end - return _1_(conn.decode(chunk)) + return _2_(conn.decode(chunk)) end end - local function _4_(err) + local function _5_(err) if err then return opts["on-failure"](err) else - do end (conn.sock):read_start(client["schedule-wrap"](handle_message)) + conn.sock:read_start(client["schedule-wrap"](handle_message)) return opts["on-success"]() end end - conn = a.merge(conn, net.connect({host = opts.host, port = opts.port, cb = client["schedule-wrap"](_4_)})) + conn = a.merge(conn, net.connect({host = opts.host, port = opts.port, cb = client["schedule-wrap"](_5_)})) return conn end -_2amodule_2a["connect"] = connect -do local _ = {connect, nil} end -return _2amodule_2a +return {send = send, connect = connect} diff --git a/lua/conjure/remote/transport/swank.lua b/lua/conjure/remote/transport/swank.lua index 3f1a105a..c6e7fe76 100644 --- a/lua/conjure/remote/transport/swank.lua +++ b/lua/conjure/remote/transport/swank.lua @@ -1,32 +1,16 @@ -- [nfnl] Compiled from fnl/conjure/remote/transport/swank.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.remote.transport.swank" -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, log = autoload("conjure.aniseed.core"), autoload("conjure.log") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["log"] = log -do local _ = {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 log = autoload("conjure.log") local function encode(msg) local n = a.count(msg) local header = string.format("%06x", (1 + n)) return (header .. msg .. "\n") end -_2amodule_2a["encode"] = encode -do local _ = {encode, nil} end local function decode(msg) local len = tonumber(string.sub(msg, 1, 7), 16) local cmd = string.sub(msg, 7, len) return cmd end -_2amodule_2a["decode"] = decode -do local _ = {decode, nil} end -return _2amodule_2a +return {encode = encode, decode = decode} From e41f24148f1402c883c55334be8fbb8e33a9cc5f Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Sat, 31 Aug 2024 09:30:05 -1000 Subject: [PATCH 3/8] Convert conjure.editor --- fnl/conjure/editor.fnl | 53 +++++++++++++++++-------------- lua/conjure/editor.lua | 72 +++++++++++------------------------------- 2 files changed, 49 insertions(+), 76 deletions(-) diff --git a/fnl/conjure/editor.fnl b/fnl/conjure/editor.fnl index b44c1be9..503c5fb7 100644 --- a/fnl/conjure/editor.fnl +++ b/fnl/conjure/editor.fnl @@ -1,31 +1,29 @@ -(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 fs (autoload :conjure.fs)) +(local nvim (autoload :conjure.aniseed.nvim)) +(local util (autoload :conjure.util)) -(module conjure.editor - {autoload {a conjure.aniseed.core - nvim conjure.aniseed.nvim - fs conjure.fs - util conjure.util}}) - -(defn- percent-fn [total-fn] +(fn percent-fn [total-fn] (fn [pc] (math.floor (* (/ (total-fn) 100) (* pc 100))))) -(defn width [] - nvim.o.columns) +(fn width [] + vim.o.columns) -(defn height [] - nvim.o.lines) +(fn height [] + vim.o.lines) -(def percent-width (percent-fn width)) -(def percent-height (percent-fn height)) +(local percent-width (percent-fn width)) +(local percent-height (percent-fn height)) -(defn cursor-left [] - (nvim.fn.screencol)) +(fn cursor-left [] + (vim.fn.screencol)) -(defn cursor-top [] - (nvim.fn.screenrow)) +(fn cursor-top [] + (vim.fn.screenrow)) -(defn go-to [path-or-win line column] +(fn go-to [path-or-win line column] (when (a.string? path-or-win) (nvim.ex.edit (fs.localise-path path-or-win))) @@ -35,13 +33,22 @@ 0) [line (a.dec column)])) -(defn go-to-mark [m] +(fn go-to-mark [m] (nvim.ex.normal_ (.. "`" m))) -(defn go-back [] +(fn go-back [] (nvim.ex.normal_ (util.replace-termcodes ""))) -(defn has-filetype? [ft] +(fn has-filetype? [ft] (a.some #(= ft $1) (nvim.fn.getcompletion ft :filetype))) -*module* +{: width + : height + : percent-width + : percent-height + : cursor-left + : cursor-top + : go-to + : go-to-mark + : go-back + : has-filetype?} diff --git a/lua/conjure/editor.lua b/lua/conjure/editor.lua index 7e97261b..695a5270 100644 --- a/lua/conjure/editor.lua +++ b/lua/conjure/editor.lua @@ -1,87 +1,53 @@ -- [nfnl] Compiled from fnl/conjure/editor.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.editor" -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, fs, nvim, util = autoload("conjure.aniseed.core"), autoload("conjure.fs"), autoload("conjure.aniseed.nvim"), autoload("conjure.util") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["fs"] = fs -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["util"] = util -do local _ = {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 fs = autoload("conjure.fs") +local nvim = autoload("conjure.aniseed.nvim") +local util = autoload("conjure.util") local function percent_fn(total_fn) - local function _1_(pc) + local function _2_(pc) return math.floor(((total_fn() / 100) * (pc * 100))) end - return _1_ + return _2_ end -_2amodule_locals_2a["percent-fn"] = percent_fn -do local _ = {percent_fn, nil} end local function width() - return nvim.o.columns + return vim.o.columns end -_2amodule_2a["width"] = width -do local _ = {width, nil} end local function height() - return nvim.o.lines + return vim.o.lines end -_2amodule_2a["height"] = height -do local _ = {height, nil} end local percent_width = percent_fn(width) -do end (_2amodule_2a)["percent-width"] = percent_width -do local _ = {nil, nil} end local percent_height = percent_fn(height) -do end (_2amodule_2a)["percent-height"] = percent_height -do local _ = {nil, nil} end local function cursor_left() - return nvim.fn.screencol() + return vim.fn.screencol() end -_2amodule_2a["cursor-left"] = cursor_left -do local _ = {cursor_left, nil} end local function cursor_top() - return nvim.fn.screenrow() + return vim.fn.screenrow() end -_2amodule_2a["cursor-top"] = cursor_top -do local _ = {cursor_top, nil} end local function go_to(path_or_win, line, column) if a["string?"](path_or_win) then nvim.ex.edit(fs["localise-path"](path_or_win)) else end - local _3_ + local _4_ if ("number" == type(path_or_win)) then - _3_ = path_or_win + _4_ = path_or_win else - _3_ = 0 + _4_ = 0 end - return nvim.win_set_cursor(_3_, {line, a.dec(column)}) + return nvim.win_set_cursor(_4_, {line, a.dec(column)}) end -_2amodule_2a["go-to"] = go_to -do local _ = {go_to, nil} end local function go_to_mark(m) return nvim.ex.normal_(("`" .. m)) end -_2amodule_2a["go-to-mark"] = go_to_mark -do local _ = {go_to_mark, nil} end local function go_back() return nvim.ex.normal_(util["replace-termcodes"]("")) end -_2amodule_2a["go-back"] = go_back -do local _ = {go_back, nil} end local function has_filetype_3f(ft) - local function _5_(_241) + local function _6_(_241) return (ft == _241) end - return a.some(_5_, nvim.fn.getcompletion(ft, "filetype")) + return a.some(_6_, nvim.fn.getcompletion(ft, "filetype")) end -_2amodule_2a["has-filetype?"] = has_filetype_3f -do local _ = {has_filetype_3f, nil} end -return _2amodule_2a +return {width = width, height = height, ["percent-width"] = percent_width, ["percent-height"] = percent_height, ["cursor-left"] = cursor_left, ["cursor-top"] = cursor_top, ["go-to"] = go_to, ["go-to-mark"] = go_to_mark, ["go-back"] = go_back, ["has-filetype?"] = has_filetype_3f} From 30eea2299d89cf26eb4cbd1d9fbe5eab6b7f4a73 Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Sat, 31 Aug 2024 13:50:38 -1000 Subject: [PATCH 4/8] Convert dynamic --- fnl/conjure-spec/dynamic_spec.fnl | 98 +++++++++++++++++++ fnl/conjure/dynamic.fnl | 25 ++--- lua/conjure-spec/dynamic_spec.lua | 156 ++++++++++++++++++++++++++++++ lua/conjure/dynamic.lua | 43 ++------ 4 files changed, 275 insertions(+), 47 deletions(-) create mode 100644 fnl/conjure-spec/dynamic_spec.fnl create mode 100644 lua/conjure-spec/dynamic_spec.lua diff --git a/fnl/conjure-spec/dynamic_spec.fnl b/fnl/conjure-spec/dynamic_spec.fnl new file mode 100644 index 00000000..4b46c375 --- /dev/null +++ b/fnl/conjure-spec/dynamic_spec.fnl @@ -0,0 +1,98 @@ +(local {: describe : it} (require :plenary.busted)) +(local assert (require :luassert.assert)) + +(local dyn (require :conjure.dynamic)) + +(describe "conjure.dynamic" + (fn [] + (describe "new-and-unbox" + (fn [] + (let [foo (dyn.new #(do :bar))] + (it "new returns a function" + (fn [] + (assert.are.equals :function (type foo)))) + (it "function is wrapped" + (fn [] + (assert.are.equals :bar (foo))))))) + + (describe "bind" + (fn [] + (let [foo (dyn.new #(do 1))] + (it "one level deep" + (fn [] + (assert.are.equals 1 (foo)))) + (it "two levels deep" + (fn [] + (dyn.bind + {foo #(do 2)} + (fn [expected] + (assert.are.equals expected (foo))) + 2))) + (it "no more than two levels deep" + (fn [] + (dyn.bind + {foo #(do 2)} + (fn [] + (assert.are.equals 2 (foo)) + (dyn.bind + {foo #(do 3)} + (fn [] + (assert.are.equals 3 (foo)))) + (dyn.bind + {foo #(error "OHNO")} + (fn [] + (let [(ok? result) (pcall foo)] + (assert.are.equals false ok?) + (assert.are.equals result "OHNO")))) + (assert.are.equals 2 (foo))))))))) + + (describe "set!" + (fn [] + (let [foo (dyn.new #(do 1))] + (it "one level deep" + (fn [] + (assert.are.equals (foo) 1))) + (it "more than two levels deep" + (fn [] + (dyn.bind + {foo #(do 2)} + (fn [] + (assert.are.equals (foo) 2) + (assert.are.equals nil (dyn.set! foo #(do 3))) + (assert.are.equals (foo) 3)))))))) + + (describe "set-root!" + (fn [] + (let [foo (dyn.new #(do 1))] + (it "one level deep" + (fn [] + (assert.are.equals (foo) 1))) + (it "three levels deep" + (fn [] + (dyn.bind + {foo #(do 2)} + (fn [] + (assert.are.equals (foo) 2) + (assert.are.equals nil (dyn.set-root! foo #(do 3))) + (assert.are.equals (foo) 2))))) + (it "remembers binding from three levels deep" + (fn [] + (assert.are.equals (foo) 3))) + (it "four levels deep" + (fn [] + (dyn.set-root! foo #(do 4)))) + (it "remembers binding from four levels deep" + (fn [] + (assert.are.equals (foo) 4)))))) + + (describe "type-guard" + (fn [] + (let [(ok? result) (pcall dyn.new :foo)] + (it "direct call of conjure.dynamic value fails" + (fn [] + (assert.are.equals false ok?) + )) + (it "returns why failed" + (fn [] + (assert.is_not_nil (string.match result "conjure.dynamic values must always be wrapped in a function")) + nil))))))) diff --git a/fnl/conjure/dynamic.fnl b/fnl/conjure/dynamic.fnl index 2264905c..67e65bd1 100644 --- a/fnl/conjure/dynamic.fnl +++ b/fnl/conjure/dynamic.fnl @@ -1,29 +1,27 @@ -(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)) -(module conjure.dynamic - {autoload {a conjure.aniseed.core}}) +(local get-stack-key :conjure.dynamic/get-stack) -(def- get-stack-key :conjure.dynamic/get-stack) - -(defn- assert-value-function! [value] +(fn assert-value-function! [value] (when (not= :function (type value)) (error "conjure.dynamic values must always be wrapped in a function"))) -(defn new [base-value] +(fn new [base-value] (assert-value-function! base-value) (var stack [base-value]) (fn [x ...] (if (= get-stack-key x) stack ((a.last stack) x ...)))) -(defn- run-binds! [f binds] +(fn run-binds! [f binds] (a.map-indexed (fn [[dyn new-value]] (assert-value-function! new-value) (f (dyn get-stack-key) new-value)) binds)) -(defn bind [binds f ...] +(fn bind [binds f ...] (run-binds! table.insert binds) (let [(ok? result) (pcall f ...)] (run-binds! #(table.remove $1) binds) @@ -31,16 +29,19 @@ result (error result)))) -(defn set! [dyn new-value] +(fn set! [dyn new-value] (assert-value-function! new-value) (let [stack (dyn get-stack-key) depth (a.count stack)] (a.assoc stack depth new-value)) nil) -(defn set-root! [dyn new-value] +(fn set-root! [dyn new-value] (assert-value-function! new-value) (a.assoc (dyn get-stack-key) 1 new-value) nil) -*module* +{: new + : bind + : set! + : set-root!} diff --git a/lua/conjure-spec/dynamic_spec.lua b/lua/conjure-spec/dynamic_spec.lua new file mode 100644 index 00000000..7586f7d9 --- /dev/null +++ b/lua/conjure-spec/dynamic_spec.lua @@ -0,0 +1,156 @@ +-- [nfnl] Compiled from fnl/conjure-spec/dynamic_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 dyn = require("conjure.dynamic") +local function _2_() + local function _3_() + local foo + local function _4_() + return "bar" + end + foo = dyn.new(_4_) + local function _5_() + return assert.are.equals("function", type(foo)) + end + it("new returns a function", _5_) + local function _6_() + return assert.are.equals("bar", foo()) + end + return it("function is wrapped", _6_) + end + describe("new-and-unbox", _3_) + local function _7_() + local foo + local function _8_() + return 1 + end + foo = dyn.new(_8_) + local function _9_() + return assert.are.equals(1, foo()) + end + it("one level deep", _9_) + local function _10_() + local function _11_() + return 2 + end + local function _12_(expected) + return assert.are.equals(expected, foo()) + end + return dyn.bind({[foo] = _11_}, _12_, 2) + end + it("two levels deep", _10_) + local function _13_() + local function _14_() + return 2 + end + local function _15_() + assert.are.equals(2, foo()) + local function _16_() + return 3 + end + local function _17_() + return assert.are.equals(3, foo()) + end + dyn.bind({[foo] = _16_}, _17_) + local function _18_() + return error("OHNO") + end + local function _19_() + local ok_3f, result = pcall(foo) + assert.are.equals(false, ok_3f) + return assert.are.equals(result, "OHNO") + end + dyn.bind({[foo] = _18_}, _19_) + return assert.are.equals(2, foo()) + end + return dyn.bind({[foo] = _14_}, _15_) + end + return it("no more than two levels deep", _13_) + end + describe("bind", _7_) + local function _20_() + local foo + local function _21_() + return 1 + end + foo = dyn.new(_21_) + local function _22_() + return assert.are.equals(foo(), 1) + end + it("one level deep", _22_) + local function _23_() + local function _24_() + return 2 + end + local function _25_() + assert.are.equals(foo(), 2) + local function _26_() + return 3 + end + assert.are.equals(nil, dyn["set!"](foo, _26_)) + return assert.are.equals(foo(), 3) + end + return dyn.bind({[foo] = _24_}, _25_) + end + return it("more than two levels deep", _23_) + end + describe("set!", _20_) + local function _27_() + local foo + local function _28_() + return 1 + end + foo = dyn.new(_28_) + local function _29_() + return assert.are.equals(foo(), 1) + end + it("one level deep", _29_) + local function _30_() + local function _31_() + return 2 + end + local function _32_() + assert.are.equals(foo(), 2) + local function _33_() + return 3 + end + assert.are.equals(nil, dyn["set-root!"](foo, _33_)) + return assert.are.equals(foo(), 2) + end + return dyn.bind({[foo] = _31_}, _32_) + end + it("three levels deep", _30_) + local function _34_() + return assert.are.equals(foo(), 3) + end + it("remembers binding from three levels deep", _34_) + local function _35_() + local function _36_() + return 4 + end + return dyn["set-root!"](foo, _36_) + end + it("four levels deep", _35_) + local function _37_() + return assert.are.equals(foo(), 4) + end + return it("remembers binding from four levels deep", _37_) + end + describe("set-root!", _27_) + local function _38_() + local ok_3f, result = pcall(dyn.new, "foo") + local function _39_() + return assert.are.equals(false, ok_3f) + end + it("direct call of conjure.dynamic value fails", _39_) + local function _40_() + assert.is_not_nil(string.match(result, "conjure.dynamic values must always be wrapped in a function")) + return nil + end + return it("returns why failed", _40_) + end + return describe("type-guard", _38_) +end +return describe("conjure.dynamic", _2_) diff --git a/lua/conjure/dynamic.lua b/lua/conjure/dynamic.lua index 86eb509a..3dd010a1 100644 --- a/lua/conjure/dynamic.lua +++ b/lua/conjure/dynamic.lua @@ -1,22 +1,8 @@ -- [nfnl] Compiled from fnl/conjure/dynamic.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.dynamic" -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 _local_1_ = require("nfnl.module") +local autoload = _local_1_["autoload"] local a = autoload("conjure.aniseed.core") -do end (_2amodule_locals_2a)["a"] = a -do local _ = {nil, nil, nil, nil, nil, nil} end local get_stack_key = "conjure.dynamic/get-stack" -_2amodule_locals_2a["get-stack-key"] = get_stack_key -do local _ = {nil, nil} end local function assert_value_function_21(value) if ("function" ~= type(value)) then return error("conjure.dynamic values must always be wrapped in a function") @@ -24,34 +10,27 @@ local function assert_value_function_21(value) return nil end end -_2amodule_locals_2a["assert-value-function!"] = assert_value_function_21 -do local _ = {assert_value_function_21, nil} end local function new(base_value) assert_value_function_21(base_value) local stack = {base_value} - local function _2_(x, ...) + local function _3_(x, ...) if (get_stack_key == x) then return stack else return a.last(stack)(x, ...) end end - return _2_ + return _3_ end -_2amodule_2a["new"] = new -do local _ = {new, nil} end local function run_binds_21(f, binds) - local function _6_(_4_) - local _arg_5_ = _4_ - local dyn = _arg_5_[1] - local new_value = _arg_5_[2] + local function _6_(_5_) + local dyn = _5_[1] + local new_value = _5_[2] assert_value_function_21(new_value) return f(dyn(get_stack_key), new_value) end return a["map-indexed"](_6_, binds) end -_2amodule_locals_2a["run-binds!"] = run_binds_21 -do local _ = {run_binds_21, nil} end local function bind(binds, f, ...) run_binds_21(table.insert, binds) local ok_3f, result = pcall(f, ...) @@ -65,8 +44,6 @@ local function bind(binds, f, ...) return error(result) end end -_2amodule_2a["bind"] = bind -do local _ = {bind, nil} end local function set_21(dyn, new_value) assert_value_function_21(new_value) do @@ -76,13 +53,9 @@ local function set_21(dyn, new_value) end return nil end -_2amodule_2a["set!"] = set_21 -do local _ = {set_21, nil} end local function set_root_21(dyn, new_value) assert_value_function_21(new_value) a.assoc(dyn(get_stack_key), 1, new_value) return nil end -_2amodule_2a["set-root!"] = set_root_21 -do local _ = {set_root_21, nil} end -return _2amodule_2a +return {new = new, bind = bind, ["set!"] = set_21, ["set-root!"] = set_root_21} From c3ab957e67dcfab944d4b9a860947bb9e640ecb0 Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Sat, 31 Aug 2024 15:19:39 -1000 Subject: [PATCH 5/8] Convert extract/searchpair. --- fnl/conjure/extract/searchpair.fnl | 49 ++++---- lua/conjure/extract/searchpair.lua | 173 ++++++++++++----------------- 2 files changed, 93 insertions(+), 129 deletions(-) diff --git a/fnl/conjure/extract/searchpair.fnl b/fnl/conjure/extract/searchpair.fnl index aebc55e5..ca2866ff 100644 --- a/fnl/conjure/extract/searchpair.fnl +++ b/fnl/conjure/extract/searchpair.fnl @@ -1,22 +1,20 @@ -(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)) -(module conjure.extract.searchpair - {autoload {a conjure.aniseed.core - nvim conjure.aniseed.nvim - str conjure.aniseed.string - config conjure.config}}) +(local str (autoload :conjure.aniseed.string)) +(local config (autoload :conjure.config)) ;; All of the code related to the searchpair / searchpairpos based form ;; extraction. If you use Tree Sitter for all of the languages you work ;; with Conjure will avoid loading this module. It's only loaded for ;; files that can't support Tree Sitter for some reason. -(defn- nil-pos? [pos] +(fn nil-pos? [pos] (or (not pos) (= 0 (unpack pos)))) -(defn- read-range [[srow scol] [erow ecol]] - (let [lines (nvim.buf_get_lines +(fn read-range [[srow scol] [erow ecol]] + (let [lines (vim.api.nvim_buf_get_lines 0 (- srow 1) erow false)] (-> lines (a.update @@ -29,36 +27,36 @@ (string.sub s scol))) (->> (str.join "\n"))))) -(defn skip-match? [] - (let [[row col] (nvim.win_get_cursor 0) - stack (nvim.fn.synstack row (a.inc col)) +(fn skip-match? [] + (let [[row col] (vim.api.nvim_win_get_cursor 0) + stack (vim.fn.synstack row (a.inc col)) stack-size (length stack)] (if (or ;; Are we in a comment, string or regular expression? (= :number (type (and (> stack-size 0) - (let [name (nvim.fn.synIDattr (. stack stack-size) :name)] + (let [name (vim.fn.synIDattr (. stack stack-size) :name)] (or (name:find "Comment$") (name:find "String$") (name:find "Regexp%?$")))))) ;; Is the character escaped? ;; https://github.com/Olical/conjure/issues/209 - (= "\\" (-> (nvim.buf_get_lines - (nvim.win_get_buf 0) (- row 1) row false) + (= "\\" (-> (vim.api.nvim_buf_get_lines + (vim.api.nvim_win_get_buf 0) (- row 1) row false) (a.first) (string.sub col col)))) 1 0))) -(defn- current-char [] - (let [[row col] (nvim.win_get_cursor 0) - [line] (nvim.buf_get_lines 0 (- row 1) row false) +(fn current-char [] + (let [[row col] (vim.api.nvim_win_get_cursor 0) + [line] (vim.api.nvim_buf_get_lines 0 (- row 1) row false) char (+ col 1)] (string.sub line char char))) -(defn- form* [[start-char end-char escape?] {: root?}] +(fn form* [[start-char end-char escape?] {: root?}] (let [;; 'W' don't Wrap around the end of the file ;; 'n' do Not move the cursor ;; 'z' start searching at the cursor column instead of Zero @@ -78,11 +76,11 @@ (.. "\\" end-char) end-char) - start (nvim.fn.searchpairpos + start (vim.fn.searchpairpos safe-start-char "" safe-end-char (.. flags "b" (if (= cursor-char start-char) "c" "")) skip-match?) - end (nvim.fn.searchpairpos + end (vim.fn.searchpairpos safe-start-char "" safe-end-char (.. flags (if (= cursor-char end-char) "c" "")) skip-match?)] @@ -93,16 +91,16 @@ :end [(a.first end) (a.dec (a.second end))]} :content (read-range start end)}))) -(defn- distance-gt [[al ac] [bl bc]] +(fn distance-gt [[al ac] [bl bc]] (or (> al bl) (and (= al bl) (> ac bc)))) -(defn- range-distance [range] +(fn range-distance [range] (let [[sl sc] range.start [el ec] range.end] [(- sl el) (- sc ec)])) -(defn form [opts] +(fn form [opts] (local forms (->> (config.get-in [:extract :form_pairs]) (a.map #(form* $1 opts)) @@ -118,4 +116,5 @@ (a.last forms) (a.first forms))) -*module* +{: skip-match? + : form} diff --git a/lua/conjure/extract/searchpair.lua b/lua/conjure/extract/searchpair.lua index 7b4a544c..ad6f5aa2 100644 --- a/lua/conjure/extract/searchpair.lua +++ b/lua/conjure/extract/searchpair.lua @@ -1,90 +1,69 @@ -- [nfnl] Compiled from fnl/conjure/extract/searchpair.fnl by https://github.com/Olical/nfnl, do not edit. -local _2amodule_name_2a = "conjure.extract.searchpair" -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, config, nvim, str = autoload("conjure.aniseed.core"), autoload("conjure.config"), autoload("conjure.aniseed.nvim"), autoload("conjure.aniseed.string") -do end (_2amodule_locals_2a)["a"] = a -_2amodule_locals_2a["config"] = config -_2amodule_locals_2a["nvim"] = nvim -_2amodule_locals_2a["str"] = str -do local _ = {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 config = autoload("conjure.config") local function nil_pos_3f(pos) return (not pos or (0 == unpack(pos))) end -_2amodule_locals_2a["nil-pos?"] = nil_pos_3f -do local _ = {nil_pos_3f, nil} end -local function read_range(_1_, _3_) - local _arg_2_ = _1_ - local srow = _arg_2_[1] - local scol = _arg_2_[2] - local _arg_4_ = _3_ - local erow = _arg_4_[1] - local ecol = _arg_4_[2] - local lines = nvim.buf_get_lines(0, (srow - 1), erow, false) - local function _5_(s) +local function read_range(_2_, _3_) + local srow = _2_[1] + local scol = _2_[2] + local erow = _3_[1] + local ecol = _3_[2] + local lines = vim.api.nvim_buf_get_lines(0, (srow - 1), erow, false) + local function _4_(s) return string.sub(s, 0, ecol) end - local function _6_(s) + local function _5_(s) return string.sub(s, scol) end - return str.join("\n", a.update(a.update(lines, #lines, _5_), 1, _6_)) + return str.join("\n", a.update(a.update(lines, #lines, _4_), 1, _5_)) end -_2amodule_locals_2a["read-range"] = read_range -do local _ = {read_range, nil} end local function skip_match_3f() - local _let_7_ = nvim.win_get_cursor(0) - local row = _let_7_[1] - local col = _let_7_[2] - local stack = nvim.fn.synstack(row, a.inc(col)) + local _let_6_ = vim.api.nvim_win_get_cursor(0) + local row = _let_6_[1] + local col = _let_6_[2] + local stack = vim.fn.synstack(row, a.inc(col)) local stack_size = #stack - local function _8_() - local name = nvim.fn.synIDattr(stack[stack_size], "name") - return (name:find("Comment$") or name:find("String$") or name:find("Regexp%?$")) + local and_7_ = (stack_size > 0) + if and_7_ then + local name = vim.fn.synIDattr(stack[stack_size], "name") + and_7_ = (name:find("Comment$") or name:find("String$") or name:find("Regexp%?$")) end - if (("number" == type(((stack_size > 0) and _8_()))) or ("\\" == string.sub(a.first(nvim.buf_get_lines(nvim.win_get_buf(0), (row - 1), row, false)), col, col))) then + local or_9_ = ("number" == type(and_7_)) + if not or_9_ then + or_9_ = ("\\" == string.sub(a.first(vim.api.nvim_buf_get_lines(vim.api.nvim_win_get_buf(0), (row - 1), row, false)), col, col)) + end + if or_9_ then return 1 else return 0 end end -_2amodule_2a["skip-match?"] = skip_match_3f -do local _ = {skip_match_3f, nil} end local function current_char() - local _let_10_ = nvim.win_get_cursor(0) - local row = _let_10_[1] - local col = _let_10_[2] - local _let_11_ = nvim.buf_get_lines(0, (row - 1), row, false) - local line = _let_11_[1] + local _let_11_ = vim.api.nvim_win_get_cursor(0) + local row = _let_11_[1] + local col = _let_11_[2] + local _let_12_ = vim.api.nvim_buf_get_lines(0, (row - 1), row, false) + local line = _let_12_[1] local char = (col + 1) return string.sub(line, char, char) end -_2amodule_locals_2a["current-char"] = current_char -do local _ = {current_char, nil} end -local function form_2a(_12_, _14_) - local _arg_13_ = _12_ - local start_char = _arg_13_[1] - local end_char = _arg_13_[2] - local escape_3f = _arg_13_[3] - local _arg_15_ = _14_ - local root_3f = _arg_15_["root?"] +local function form_2a(_13_, _14_) + local start_char = _13_[1] + local end_char = _13_[2] + local escape_3f = _13_[3] + local root_3f = _14_["root?"] local flags - local function _16_() - if root_3f then - return "r" - else - return "" - end + local _15_ + if root_3f then + _15_ = "r" + else + _15_ = "" end - flags = ("Wnz" .. _16_()) + flags = ("Wnz" .. _15_) local cursor_char = current_char() local safe_start_char if escape_3f then @@ -99,69 +78,55 @@ local function form_2a(_12_, _14_) safe_end_char = end_char end local start - local function _19_() - if (cursor_char == start_char) then - return "c" - else - return "" - end + local _19_ + if (cursor_char == start_char) then + _19_ = "c" + else + _19_ = "" end - start = nvim.fn.searchpairpos(safe_start_char, "", safe_end_char, (flags .. "b" .. _19_()), skip_match_3f) + start = vim.fn.searchpairpos(safe_start_char, "", safe_end_char, (flags .. "b" .. _19_), skip_match_3f) local _end - local function _20_() - if (cursor_char == end_char) then - return "c" - else - return "" - end + local _21_ + if (cursor_char == end_char) then + _21_ = "c" + else + _21_ = "" end - _end = nvim.fn.searchpairpos(safe_start_char, "", safe_end_char, (flags .. _20_()), skip_match_3f) + _end = vim.fn.searchpairpos(safe_start_char, "", safe_end_char, (flags .. _21_), skip_match_3f) if (not nil_pos_3f(start) and not nil_pos_3f(_end)) then return {range = {start = {a.first(start), a.dec(a.second(start))}, ["end"] = {a.first(_end), a.dec(a.second(_end))}}, content = read_range(start, _end)} else return nil end end -_2amodule_locals_2a["form*"] = form_2a -do local _ = {form_2a, nil} end -local function distance_gt(_22_, _24_) - local _arg_23_ = _22_ - local al = _arg_23_[1] - local ac = _arg_23_[2] - local _arg_25_ = _24_ - local bl = _arg_25_[1] - local bc = _arg_25_[2] +local function distance_gt(_24_, _25_) + local al = _24_[1] + local ac = _24_[2] + local bl = _25_[1] + local bc = _25_[2] return ((al > bl) or ((al == bl) and (ac > bc))) end -_2amodule_locals_2a["distance-gt"] = distance_gt -do local _ = {distance_gt, nil} end local function range_distance(range) - local _let_26_ = range.start - local sl = _let_26_[1] - local sc = _let_26_[2] - local _let_27_ = range["end"] - local el = _let_27_[1] - local ec = _let_27_[2] + local sl = range.start[1] + local sc = range.start[2] + local el = range["end"][1] + local ec = range["end"][2] return {(sl - el), (sc - ec)} end -_2amodule_locals_2a["range-distance"] = range_distance -do local _ = {range_distance, nil} end local function form(opts) local forms - local function _28_(_241) + local function _26_(_241) return form_2a(_241, opts) end - forms = a.filter(a["table?"], a.map(_28_, config["get-in"]({"extract", "form_pairs"}))) - local function _29_(_241, _242) + forms = a.filter(a["table?"], a.map(_26_, config["get-in"]({"extract", "form_pairs"}))) + local function _27_(_241, _242) return distance_gt(range_distance(_241.range), range_distance(_242.range)) end - table.sort(forms, _29_) + table.sort(forms, _27_) if opts["root?"] then return a.last(forms) else return a.first(forms) end end -_2amodule_2a["form"] = form -do local _ = {form, nil} end -return _2amodule_2a +return {["skip-match?"] = skip_match_3f, form = form} From a82f6db6f7e9b53caf325da438ba59d0f089410c Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Sun, 1 Sep 2024 07:27:19 -1000 Subject: [PATCH 6/8] Convert fennel/aniseed client --- .../client/fennel/aniseed_spec.fnl | 109 +++++++++ fnl/conjure/client/fennel/aniseed.fnl | 100 +++++---- .../client/fennel/aniseed_spec.lua | 125 +++++++++++ lua/conjure/client/fennel/aniseed.lua | 207 ++++++------------ 4 files changed, 363 insertions(+), 178 deletions(-) create mode 100644 fnl/conjure-spec/client/fennel/aniseed_spec.fnl create mode 100644 lua/conjure-spec/client/fennel/aniseed_spec.lua diff --git a/fnl/conjure-spec/client/fennel/aniseed_spec.fnl b/fnl/conjure-spec/client/fennel/aniseed_spec.fnl new file mode 100644 index 00000000..e947e226 --- /dev/null +++ b/fnl/conjure-spec/client/fennel/aniseed_spec.fnl @@ -0,0 +1,109 @@ +(local {: describe : it} (require :plenary.busted)) +(local assert (require :luassert.assert)) +(local a (require :nfnl.core)) +(local ani (require :conjure.client.fennel.aniseed)) + +(describe "client.fennel.aniseed" + (fn [] + (local ex-mod "test.foo.bar") + (local ex-file "/some-big/ol/path/test/foo/bar.fnl") + (local ex-file2 "/some-big/ol/path/test/foo/bar/init.fnl") + (local ex-no-file "/some-big/ol/path/test/foo/bar/no/init.fnl") + + (fn contains? [s substr] + (values + substr + (if (string.find s substr) + substr + s))) + + (describe "module-name" + (fn [] + (tset package.loaded ex-mod {:my :module}) + + (it "default name" + (fn [] + (assert.are.equals ani.default-module-name (ani.module-name nil nil)))) + (it "ex-mod and ex-file" + (fn [] + (assert.are.equals ex-mod (ani.module-name ex-mod ex-file)))) + (it "ex-file and no ex-mod" + (fn [] + (assert.are.equals ex-mod (ani.module-name nil ex-file)))) + (it "ex-file2 and no ex-mod" + (fn [] + (assert.are.equals ex-mod (ani.module-name nil ex-file2)))) + (it "default module name when no ex-file" + (fn [] + (assert.are.equals ani.default-module-name (ani.module-name nil ex-no-file)))) + + (tset package.loaded ex-mod nil) + )) + (describe "eval-str" + (fn [] + (fn eval! [code] + (var result nil) + (var raw nil) + (ani.eval-str + {:code code + :context "foo.bar" + :passive? true + :file-path "foo/bar.fnl" + :on-result #(set result $1) + :on-result-raw #(set raw $1)}) + {:result result + :raw raw}) + + (it "evaluates a form" + (fn [] + (assert.same {:raw [30] :result "30"} (eval! "(+ 10 20)")))) + (it "eval a function definition" + (fn [] + (let [{: raw : result} (eval! "(fn hi [] 10)")] + (assert.are.equals :function (type (a.first raw))) + (assert.are.equals :string (type result)) + (assert.is_not_nil (contains? result "#module-name file-path) default-module-name) default-module-name)) -(defn repl [opts] +(fn repl [opts] (let [filename (a.get opts :filename)] (or ;; Reuse an existing REPL. (and (not (a.get opts :fresh?)) (a.get repls filename)) @@ -120,7 +118,7 @@ ;; Return the new REPL! repl)))) -(defn display-result [opts] +(fn display-result [opts] (when opts (let [{: ok? : results} opts result-str (or @@ -140,7 +138,7 @@ (when opts.on-result (opts.on-result result-str))))) -(defn eval-str [opts] +(fn eval-str [opts] ((client.wrap (fn [] (let [out (anic :nu :with-out-str @@ -171,16 +169,16 @@ (log.append (text.prefixed-lines (text.trim-last-newline out) "; (out) "))) (display-result opts)))))) -(defn doc-str [opts] +(fn doc-str [opts] (a.assoc opts :code (.. ",doc " opts.code)) (eval-str opts)) -(defn eval-file [opts] +(fn eval-file [opts] (set opts.code (a.slurp opts.file-path)) (when opts.code (eval-str opts))) -(defn- wrapped-test [req-lines f] +(fn wrapped-test [req-lines f] (log.append req-lines {:break? true}) (let [res (anic :nu :with-out-str f)] (log.append @@ -189,17 +187,17 @@ res) (text.prefixed-lines "; "))))) -(defn run-buf-tests [] +(fn run-buf-tests [] (let [c (extract.context)] (when c (wrapped-test [(.. "; run-buf-tests (" c ")")] #(anic :test :run c))))) -(defn run-all-tests [] +(fn run-all-tests [] (wrapped-test ["; run-all-tests"] (ani :test :run-all))) -(defn on-filetype [] +(fn on-filetype [] (mapping.buf :FnlRunBufTests (cfg [:mapping :run_buf_tests]) #(run-buf-tests) @@ -220,7 +218,7 @@ #(reset-all-repls) {:desc "Reset all REPL states"})) -(defn value->completions [x] +(fn value->completions [x] (when (= :table (type x)) (->> (if (. x :aniseed/autoload-enabled?) (do @@ -238,7 +236,7 @@ :menu nil :info nil}))))) -(defn completions [opts] +(fn completions [opts] (let [code (when (not (str.blank? opts.prefix)) (let [prefix (string.gsub opts.prefix ".$" "")] (.. "((. (require :" *module-name* ") :value->completions) " prefix ")"))) @@ -276,4 +274,22 @@ (when (not ok?) (opts.cb locals)))) -*module* +{: buf-suffix + : comment-node? + : comment-prefix + : completions + : context-pattern + : default-module-name + : display-result + : doc-str + : eval-file + : eval-str + : form-node? + : module-name + : on-filetype + : repl + : reset-all-repls + : reset-repl + : run-all-tests + : run-buf-tests + : value->completions } diff --git a/lua/conjure-spec/client/fennel/aniseed_spec.lua b/lua/conjure-spec/client/fennel/aniseed_spec.lua new file mode 100644 index 00000000..0109d545 --- /dev/null +++ b/lua/conjure-spec/client/fennel/aniseed_spec.lua @@ -0,0 +1,125 @@ +-- [nfnl] Compiled from fnl/conjure-spec/client/fennel/aniseed_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 ani = require("conjure.client.fennel.aniseed") +local function _2_() + local ex_mod = "test.foo.bar" + local ex_file = "/some-big/ol/path/test/foo/bar.fnl" + local ex_file2 = "/some-big/ol/path/test/foo/bar/init.fnl" + local ex_no_file = "/some-big/ol/path/test/foo/bar/no/init.fnl" + local function contains_3f(s, substr) + local function _3_() + if string.find(s, substr) then + return substr + else + return s + end + end + return substr, _3_() + end + local function _4_() + package.loaded[ex_mod] = {my = "module"} + local function _5_() + return assert.are.equals(ani["default-module-name"], ani["module-name"](nil, nil)) + end + it("default name", _5_) + local function _6_() + return assert.are.equals(ex_mod, ani["module-name"](ex_mod, ex_file)) + end + it("ex-mod and ex-file", _6_) + local function _7_() + return assert.are.equals(ex_mod, ani["module-name"](nil, ex_file)) + end + it("ex-file and no ex-mod", _7_) + local function _8_() + return assert.are.equals(ex_mod, ani["module-name"](nil, ex_file2)) + end + it("ex-file2 and no ex-mod", _8_) + local function _9_() + return assert.are.equals(ani["default-module-name"], ani["module-name"](nil, ex_no_file)) + end + it("default module name when no ex-file", _9_) + package.loaded[ex_mod] = nil + return nil + end + describe("module-name", _4_) + local function _10_() + local function eval_21(code) + local result = nil + local raw = nil + local function _11_(_241) + result = _241 + return nil + end + local function _12_(_241) + raw = _241 + return nil + end + ani["eval-str"]({code = code, context = "foo.bar", ["passive?"] = true, ["file-path"] = "foo/bar.fnl", ["on-result"] = _11_, ["on-result-raw"] = _12_}) + return {result = result, raw = raw} + end + local function _13_() + return assert.same({raw = {30}, result = "30"}, eval_21("(+ 10 20)")) + end + it("evaluates a form", _13_) + local function _14_() + local _let_15_ = eval_21("(fn hi [] 10)") + local raw = _let_15_["raw"] + local result = _let_15_["result"] + assert.are.equals("function", type(a.first(raw))) + assert.are.equals("string", type(result)) + return assert.is_not_nil(contains_3f(result, "#completions"] = value__3ecompletions -do local _ = {value__3ecompletions, nil} end local function completions(opts) local code if not str["blank?"](opts.prefix) then local prefix = string.gsub(opts.prefix, ".$", "") - code = ("((. (require :" .. _2amodule_name_2a .. ") :value->completions) " .. prefix .. ")") + code = ("((. (require :" .. __fnl_global___2amodule_2dname_2a .. ") :value->completions) " .. prefix .. ")") else code = nil end @@ -368,6 +305,4 @@ local function completions(opts) return nil end end -_2amodule_2a["completions"] = completions -do local _ = {completions, nil} end -return _2amodule_2a +return {["buf-suffix"] = buf_suffix, ["comment-node?"] = comment_node_3f, ["comment-prefix"] = comment_prefix, completions = completions, ["context-pattern"] = context_pattern, ["default-module-name"] = default_module_name, ["display-result"] = display_result, ["doc-str"] = doc_str, ["eval-file"] = eval_file, ["eval-str"] = eval_str, ["form-node?"] = form_node_3f, ["module-name"] = module_name, ["on-filetype"] = on_filetype, repl = repl, ["reset-all-repls"] = reset_all_repls, ["reset-repl"] = reset_repl, ["run-all-tests"] = run_all_tests, ["run-buf-tests"] = run_buf_tests, ["value->completions"] = value__3ecompletions} From d9a6a62b682ba18c8f0962797e9432a38b330421 Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Sun, 1 Sep 2024 07:34:15 -1000 Subject: [PATCH 7/8] Forgot to commit fennel/aniseed.fnl --- fnl/conjure/client/fennel/aniseed.fnl | 14 +++++++------- lua/conjure/client/fennel/aniseed.lua | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/fnl/conjure/client/fennel/aniseed.fnl b/fnl/conjure/client/fennel/aniseed.fnl index ca1cc7dc..21b598c3 100644 --- a/fnl/conjure/client/fennel/aniseed.fnl +++ b/fnl/conjure/client/fennel/aniseed.fnl @@ -1,16 +1,16 @@ (local {: autoload} (require :nfnl.module)) -(local nvim (autoload :conjure.aniseed.nvim)) (local a (autoload :conjure.aniseed.core)) -(local str (autoload :conjure.aniseed.string)) -(local view (autoload :conjure.aniseed.view)) (local client (autoload :conjure.client)) -(local mapping (autoload :conjure.mapping)) -(local fs (autoload :conjure.fs)) -(local text (autoload :conjure.text)) -(local log (autoload :conjure.log)) (local config (autoload :conjure.config)) (local extract (autoload :conjure.extract)) +(local fs (autoload :conjure.fs)) +(local log (autoload :conjure.log)) +(local mapping (autoload :conjure.mapping)) +(local nvim (autoload :conjure.aniseed.nvim)) +(local str (autoload :conjure.aniseed.string)) +(local text (autoload :conjure.text)) (local ts (autoload :conjure.tree-sitter)) +(local view (autoload :conjure.aniseed.view)) (local comment-node? ts.lisp-comment-node?) (fn form-node? [node] diff --git a/lua/conjure/client/fennel/aniseed.lua b/lua/conjure/client/fennel/aniseed.lua index 3fc8e535..01e51de8 100644 --- a/lua/conjure/client/fennel/aniseed.lua +++ b/lua/conjure/client/fennel/aniseed.lua @@ -1,18 +1,18 @@ -- [nfnl] Compiled from fnl/conjure/client/fennel/aniseed.fnl by https://github.com/Olical/nfnl, do not edit. local _local_1_ = require("nfnl.module") local autoload = _local_1_["autoload"] -local nvim = autoload("conjure.aniseed.nvim") local a = autoload("conjure.aniseed.core") -local str = autoload("conjure.aniseed.string") -local view = autoload("conjure.aniseed.view") local client = autoload("conjure.client") -local mapping = autoload("conjure.mapping") -local fs = autoload("conjure.fs") -local text = autoload("conjure.text") -local log = autoload("conjure.log") local config = autoload("conjure.config") local extract = autoload("conjure.extract") +local fs = autoload("conjure.fs") +local log = autoload("conjure.log") +local mapping = autoload("conjure.mapping") +local nvim = autoload("conjure.aniseed.nvim") +local str = autoload("conjure.aniseed.string") +local text = autoload("conjure.text") local ts = autoload("conjure.tree-sitter") +local view = autoload("conjure.aniseed.view") local comment_node_3f = ts["lisp-comment-node?"] local function form_node_3f(node) return ts["node-surrounded-by-form-pair-chars?"](node, {{"#(", ")"}}) From 8345f02f6038a65801fac1901fde32a370bcb178 Mon Sep 17 00:00:00 2001 From: Russ Tokuyama Date: Sun, 1 Sep 2024 08:05:42 -1000 Subject: [PATCH 8/8] Fix client_spec.fnl failing in Circle CI build. --- fnl/conjure-spec/client_spec.fnl | 3 ++- lua/conjure-spec/client_spec.lua | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/fnl/conjure-spec/client_spec.fnl b/fnl/conjure-spec/client_spec.fnl index 38f07f72..400dc649 100644 --- a/fnl/conjure-spec/client_spec.fnl +++ b/fnl/conjure-spec/client_spec.fnl @@ -1,5 +1,6 @@ (local {: describe : it : before-each } (require :plenary.busted)) (local assert (require :luassert.assert)) +(local nc (require :nfnl.core)) (local client (require :conjure.client)) (describe "multiple-states? before a change" @@ -113,5 +114,5 @@ (client.each-loaded-client (fn [] (table.insert suffixes (client.get :buf-suffix)))) - (assert.same [:.sql :.fnl] suffixes) + (assert.same (nc.sort [:.sql :.fnl]) (nc.sort suffixes)) nil)))) diff --git a/lua/conjure-spec/client_spec.lua b/lua/conjure-spec/client_spec.lua index 8c4132c8..c7ae6b12 100644 --- a/lua/conjure-spec/client_spec.lua +++ b/lua/conjure-spec/client_spec.lua @@ -4,6 +4,7 @@ local describe = _local_1_["describe"] local it = _local_1_["it"] local before_each = _local_1_["before-each"] local assert = require("luassert.assert") +local nc = require("nfnl.core") local client = require("conjure.client") local function _2_() local function _3_() @@ -126,7 +127,7 @@ local function _31_() return table.insert(suffixes, client.get("buf-suffix")) end client["each-loaded-client"](_33_) - assert.same({".sql", ".fnl"}, suffixes) + assert.same(nc.sort({".sql", ".fnl"}), nc.sort(suffixes)) return nil end return it("runs a function for each loaded client", _32_)