diff --git a/dev/clojure/src/dev/sandbox.cljc b/dev/clojure/src/dev/sandbox.cljc index 59fada09..852fe3ae 100644 --- a/dev/clojure/src/dev/sandbox.cljc +++ b/dev/clojure/src/dev/sandbox.cljc @@ -14,6 +14,12 @@ [a b] (+ a b)) +#{:a :b :c} +#?(:clj :hi-clojure :cljs :hi-cljs) +#(+ 1 %) +'(+ 10 20) +`(+ 10 20) + (println "\033[0;31mHello, World!\033[0m") {:xyz diff --git a/fnl/conjure/client/clojure/nrepl/init.fnl b/fnl/conjure/client/clojure/nrepl/init.fnl index 1632f67c..e0a5c617 100644 --- a/fnl/conjure/client/clojure/nrepl/init.fnl +++ b/fnl/conjure/client/clojure/nrepl/init.fnl @@ -5,6 +5,7 @@ bridge conjure.bridge eval conjure.eval str conjure.aniseed.string + text conjure.text config conjure.config action conjure.client.clojure.nrepl.action server conjure.client.clojure.nrepl.server @@ -15,7 +16,20 @@ (def buf-suffix ".cljc") (def comment-prefix "; ") (def- cfg (config.get-in-fn [:client :clojure :nrepl])) -(def form-node? ts.node-surrounded-by-form-pair-chars?) + +(def- reader-macro-pairs + [["#{" "}"] + ["#(" ")"] + ["#?(" ")"] + ["'(" ")"] + ["'[" "]"] + ["'{" "}"] + ["`(" ")"] + ["`[" "]"] + ["`{" "}"]]) + +(defn form-node? [node] + (ts.node-surrounded-by-form-pair-chars? node reader-macro-pairs)) (config.merge {:client diff --git a/fnl/conjure/client/fennel/aniseed.fnl b/fnl/conjure/client/fennel/aniseed.fnl index 60c74f29..d45247cf 100644 --- a/fnl/conjure/client/fennel/aniseed.fnl +++ b/fnl/conjure/client/fennel/aniseed.fnl @@ -12,10 +12,12 @@ extract conjure.extract ts conjure.tree-sitter}}) +(defn form-node? [node] + (ts.node-surrounded-by-form-pair-chars? node [["#(" ")"]])) + (def buf-suffix ".fnl") (def context-pattern "%(%s*module%s+(.-)[%s){]") (def comment-prefix "; ") -(def form-node? ts.node-surrounded-by-form-pair-chars?) (config.merge {:client diff --git a/fnl/conjure/tree-sitter.fnl b/fnl/conjure/tree-sitter.fnl index 94a123d7..ee203cbc 100644 --- a/fnl/conjure/tree-sitter.fnl +++ b/fnl/conjure/tree-sitter.fnl @@ -73,13 +73,18 @@ (when (leaf? node) node))) -(defn node-surrounded-by-form-pair-chars? [node] - (let [first-and-last-chars (text.first-and-last-chars - (node->str node))] +(defn node-surrounded-by-form-pair-chars? [node extra-pairs] + (let [node-str (node->str node) + first-and-last-chars (text.first-and-last-chars node-str)] (or (a.some (fn [[start end]] (= first-and-last-chars (.. start end))) (config.get-in [:extract :form_pairs])) + (a.some + (fn [[start end]] + (and (text.starts-with node-str start) + (text.ends-with node-str end))) + extra-pairs) false))) (defn get-form [node] diff --git a/lua/conjure/client/clojure/nrepl/init.lua b/lua/conjure/client/clojure/nrepl/init.lua index a2a9a72e..97018d7d 100644 --- a/lua/conjure/client/clojure/nrepl/init.lua +++ b/lua/conjure/client/clojure/nrepl/init.lua @@ -11,7 +11,7 @@ do _2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"] end local autoload = (require("conjure.aniseed.autoload")).autoload -local a, action, bridge, client, config, eval, mapping, nvim, parse, server, str, ts = autoload("conjure.aniseed.core"), autoload("conjure.client.clojure.nrepl.action"), autoload("conjure.bridge"), autoload("conjure.client"), autoload("conjure.config"), autoload("conjure.eval"), autoload("conjure.mapping"), autoload("conjure.aniseed.nvim"), autoload("conjure.client.clojure.nrepl.parse"), autoload("conjure.client.clojure.nrepl.server"), autoload("conjure.aniseed.string"), autoload("conjure.tree-sitter") +local a, action, bridge, client, config, eval, mapping, nvim, parse, server, str, text, ts = autoload("conjure.aniseed.core"), autoload("conjure.client.clojure.nrepl.action"), autoload("conjure.bridge"), autoload("conjure.client"), autoload("conjure.config"), autoload("conjure.eval"), autoload("conjure.mapping"), autoload("conjure.aniseed.nvim"), autoload("conjure.client.clojure.nrepl.parse"), autoload("conjure.client.clojure.nrepl.server"), autoload("conjure.aniseed.string"), autoload("conjure.text"), autoload("conjure.tree-sitter") do end (_2amodule_locals_2a)["a"] = a _2amodule_locals_2a["action"] = action _2amodule_locals_2a["bridge"] = bridge @@ -23,6 +23,7 @@ _2amodule_locals_2a["nvim"] = nvim _2amodule_locals_2a["parse"] = parse _2amodule_locals_2a["server"] = server _2amodule_locals_2a["str"] = str +_2amodule_locals_2a["text"] = text _2amodule_locals_2a["ts"] = ts local buf_suffix = ".cljc" _2amodule_2a["buf-suffix"] = buf_suffix @@ -30,7 +31,11 @@ local comment_prefix = "; " _2amodule_2a["comment-prefix"] = comment_prefix local cfg = config["get-in-fn"]({"client", "clojure", "nrepl"}) do end (_2amodule_locals_2a)["cfg"] = cfg -local form_node_3f = ts["node-surrounded-by-form-pair-chars?"] +local reader_macro_pairs = {{"#{", "}"}, {"#(", ")"}, {"#?(", ")"}, {"'(", ")"}, {"'[", "]"}, {"'{", "}"}, {"`(", ")"}, {"`[", "]"}, {"`{", "}"}} +_2amodule_locals_2a["reader-macro-pairs"] = reader_macro_pairs +local function form_node_3f(node) + return ts["node-surrounded-by-form-pair-chars?"](node, reader_macro_pairs) +end _2amodule_2a["form-node?"] = form_node_3f config.merge({client = {clojure = {nrepl = {connection = {default_host = "localhost", port_files = {".nrepl-port", ".shadow-cljs/nrepl.port"}, auto_repl = {enabled = true, hidden = false, cmd = "bb nrepl-server localhost:8794", port_file = ".nrepl-port", port = "8794"}}, eval = {pretty_print = true, raw_out = false, auto_require = true, print_quota = nil, print_function = "conjure.internal/pprint", print_options = {length = 500, level = 50}}, interrupt = {sample_limit = 0.3}, refresh = {after = nil, before = nil, dirs = nil}, test = {current_form_names = {"deftest"}, raw_out = false, runner = "clojure", call_suffix = nil}, mapping = {disconnect = "cd", connect_port_file = "cf", interrupt = "ei", last_exception = "ve", result_1 = "v1", result_2 = "v2", result_3 = "v3", view_source = "vs", session_clone = "sc", session_fresh = "sf", session_close = "sq", session_close_all = "sQ", session_list = "sl", session_next = "sn", session_prev = "sp", session_select = "ss", run_all_tests = "ta", run_current_ns_tests = "tn", run_alternate_ns_tests = "tN", run_current_test = "tc", refresh_changed = "rr", refresh_all = "ra", refresh_clear = "rc"}, completion = {cljs = {use_suitable = true}, with_context = false}}}}}) local function context(header) diff --git a/lua/conjure/client/fennel/aniseed.lua b/lua/conjure/client/fennel/aniseed.lua index e341e263..56a65ab7 100644 --- a/lua/conjure/client/fennel/aniseed.lua +++ b/lua/conjure/client/fennel/aniseed.lua @@ -24,14 +24,16 @@ _2amodule_locals_2a["str"] = str _2amodule_locals_2a["text"] = text _2amodule_locals_2a["ts"] = ts _2amodule_locals_2a["view"] = view +local function form_node_3f(node) + return ts["node-surrounded-by-form-pair-chars?"](node, {{"#(", ")"}}) +end +_2amodule_2a["form-node?"] = form_node_3f local buf_suffix = ".fnl" _2amodule_2a["buf-suffix"] = buf_suffix local context_pattern = "%(%s*module%s+(.-)[%s){]" _2amodule_2a["context-pattern"] = context_pattern local comment_prefix = "; " _2amodule_2a["comment-prefix"] = comment_prefix -local form_node_3f = ts["node-surrounded-by-form-pair-chars?"] -_2amodule_2a["form-node?"] = form_node_3f config.merge({client = {fennel = {aniseed = {mapping = {run_buf_tests = "tt", run_all_tests = "ta", reset_repl = "rr", reset_all_repls = "ra"}, aniseed_module_prefix = "conjure.aniseed.", use_metadata = true}}}}) local cfg = config["get-in-fn"]({"client", "fennel", "aniseed"}) do end (_2amodule_locals_2a)["cfg"] = cfg diff --git a/lua/conjure/tree-sitter.lua b/lua/conjure/tree-sitter.lua index 467eea2f..ca0d9c24 100644 --- a/lua/conjure/tree-sitter.lua +++ b/lua/conjure/tree-sitter.lua @@ -106,15 +106,22 @@ local function get_leaf(node) end end _2amodule_2a["get-leaf"] = get_leaf -local function node_surrounded_by_form_pair_chars_3f(node) - local first_and_last_chars = text["first-and-last-chars"](node__3estr(node)) +local function node_surrounded_by_form_pair_chars_3f(node, extra_pairs) + local node_str = node__3estr(node) + local first_and_last_chars = text["first-and-last-chars"](node_str) local function _14_(_12_) local _arg_13_ = _12_ local start = _arg_13_[1] local _end = _arg_13_[2] return (first_and_last_chars == (start .. _end)) end - return (a.some(_14_, config["get-in"]({"extract", "form_pairs"})) or false) + local function _17_(_15_) + local _arg_16_ = _15_ + local start = _arg_16_[1] + local _end = _arg_16_[2] + return (text["starts-with"](node_str, start) and text["ends-with"](node_str, _end)) + end + return (a.some(_14_, config["get-in"]({"extract", "form_pairs"})) or a.some(_17_, extra_pairs) or false) end _2amodule_2a["node-surrounded-by-form-pair-chars?"] = node_surrounded_by_form_pair_chars_3f local function get_form(node)