Skip to content

Commit 22f62e9

Browse files
committed
Merge branch 'develop'
2 parents 20f5a76 + ca55e4e commit 22f62e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+7690
-13946
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
build:
44
docker:
5-
- image: olical/aniseed-circleci:1.0.0
5+
- image: olical/aniseed-circleci:1.1.0
66
steps:
77
- checkout
88
- run: make deps

README.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Use your favourite plugin manager, mine is https://github.com/junegunn/vim-plug[
5454

5555
[source,viml]
5656
----
57-
Plug 'Olical/conjure', {'tag': 'v4.23.0'}
57+
Plug 'Olical/conjure', {'tag': 'v4.24.0'}
5858
----
5959

6060
You'll need to be on the latest stable Neovim for all of the features (such as floating windows) to work. If you see errors, please check your Neovim version before raising an issue.

doc/conjure-client-fennel-aniseed.txt

+14
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,18 @@ All configuration can be set as described in |conjure-configuration|.
101101
Run all loaded tests.
102102
Default: `"ta"`
103103

104+
*g:conjure#client#fennel#aniseed#mapping#reset_repl*
105+
`g:conjure#client#fennel#aniseed#mapping#reset_repl`
106+
Reset the REPL for your current buffer. Use this if you need to
107+
clear the local state in your REPL or you've somehow evaluated
108+
unbalanced parenthesis.
109+
Default: `"rr"`
110+
111+
*g:conjure#client#fennel#aniseed#mapping#reset_all_repls*
112+
`g:conjure#client#fennel#aniseed#mapping#reset_all_repls`
113+
Reset all currently loaded REPLs. Use this if you've maybe messed
114+
up a few of your REPLs and you'd like to start fresh without
115+
restarting Neovim.
116+
Default: `"ra"`
117+
104118
vim:tw=78:sw=2:ts=2:ft=help:norl:et:listchars=

doc/conjure.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
*conjure*
12
______ _ ~
23
/ ____/___ ____ (_)_ __________ ~
34
/ / / __ \/ __ \ / / / / / ___/ _ \~

fnl/conjure/client/clojure/nrepl/action.fnl

+4-3
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@
184184
(a.nil? info)
185185
(log.append ["; Nothing found via CIDER's info either"])
186186

187-
info.javadoc
187+
(= :table (type info.javadoc))
188188
(log.append (java-info->lines info))
189189

190-
info.doc
190+
(= :string (type info.doc))
191191
(log.append
192192
(a.concat
193193
[(.. "; " info.ns "/" info.name)
@@ -612,7 +612,8 @@
612612
(when arglists
613613
(table.concat arglists " "))]
614614
" ")
615-
:info info
615+
:info (when (= :string (type info))
616+
info)
616617
:kind (when (not (a.empty? kind))
617618
(string.upper
618619
(string.sub kind 1 1)))})

fnl/conjure/client/fennel/aniseed.fnl

+100-21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
view conjure.aniseed.view
66
client conjure.client
77
mapping conjure.mapping
8+
fs conjure.fs
89
text conjure.text
910
log conjure.log
1011
config conjure.config
@@ -19,7 +20,9 @@
1920
{:fennel
2021
{:aniseed
2122
{:mapping {:run_buf_tests "tt"
22-
:run_all_tests "ta"}
23+
:run_all_tests "ta"
24+
:reset_repl "rr"
25+
:reset_all_repls "ra"}
2326
:aniseed_module_prefix :conjure.aniseed.
2427
:use_metadata true}}}})
2528

@@ -38,14 +41,81 @@
3841
(defn- anic [mod f-name ...]
3942
((ani mod f-name) ...))
4043

44+
(defonce- repls {})
45+
46+
(defn reset-repl [filename]
47+
(let [filename (or filename (fs.localise-path (extract.file-path)))]
48+
(tset repls filename nil)
49+
(log.append [(.. "; Reset REPL for " filename)] {:break? true})))
50+
51+
(defn reset-all-repls []
52+
(a.run!
53+
(fn [filename]
54+
(tset repls filename nil))
55+
(a.keys repls))
56+
(log.append [(.. "; Reset all REPLs")] {:break? true}))
57+
58+
(def default-module-name "conjure.user")
59+
60+
(defn module-name [context file-path]
61+
(if
62+
context context
63+
file-path (or (fs.file-path->module-name file-path) default-module-name)
64+
default-module-name))
65+
66+
(defn repl [opts]
67+
(let [filename (a.get opts :filename)]
68+
(or ;; Reuse an existing REPL.
69+
(and (not (a.get opts :fresh?)) (a.get repls filename))
70+
71+
;; Build a new REPL.
72+
(let [;; Shared between the error-handler function (created at the same time as the REPL).
73+
;; And each individual eval call. This allows us to capture errors from different call stacks.
74+
ret {}
75+
76+
;; Set up the error-handler function on the creation of the REPL.
77+
;; Will place any errors in the ret table.
78+
_ (tset opts :error-handler
79+
(fn [err]
80+
(set ret.ok? false)
81+
(set ret.results [err])))
82+
83+
;; Instantiate the raw REPL, we'll wrap this a little first though.
84+
eval! (anic :eval :repl opts)
85+
86+
;; Build our REPL function.
87+
repl (fn [code]
88+
;; Reset the ret table before running anything.
89+
(set ret.ok? nil)
90+
(set ret.results nil)
91+
92+
;; Run the code, either capturing a result or an error.
93+
;; If there's no error in ret we can place the results in the ret table.
94+
(let [results (eval! code)]
95+
(when (a.nil? ret.ok?)
96+
(set ret.ok? true)
97+
(set ret.results results))
98+
;; Finally this good or bad result is returned.
99+
ret))]
100+
101+
;; Set up the REPL in the module context.
102+
(repl (.. "(module " (a.get opts :moduleName) ")"))
103+
104+
;; Store the REPL for future reuse.
105+
(tset repls filename repl)
106+
107+
;; Return the new REPL!
108+
repl))))
109+
41110
(defn display-result [opts]
42111
(when opts
43112
(let [{: ok? : results} opts
44-
result-str (if ok?
45-
(if (a.empty? results)
46-
"nil"
47-
(str.join "\n" (a.map view.serialise results)))
48-
(a.first results))
113+
result-str (or
114+
(if ok?
115+
(when (not (a.empty? results))
116+
(str.join "\n" (a.map view.serialise results)))
117+
(a.first results))
118+
"nil")
49119
result-lines (str.split result-str "\n")]
50120
(when (not opts.passive?)
51121
(log.append
@@ -60,18 +130,23 @@
60130
(defn eval-str [opts]
61131
((client.wrap
62132
(fn []
63-
(let [code (.. (.. "(module " (or opts.context "aniseed.user") ") ")
64-
opts.code "\n")
65-
out (anic :nu :with-out-str
133+
(let [out (anic :nu :with-out-str
66134
(fn []
67135
(when (and (cfg [:use_metadata])
68136
(not package.loaded.fennel))
69137
(set package.loaded.fennel (anic :fennel :impl)))
70138

71-
(let [[ok? & results]
72-
[(anic :eval :str code
73-
{:filename opts.file-path
74-
:useMetadata (cfg [:use_metadata])})]]
139+
(let [eval! (repl {:filename opts.file-path
140+
:moduleName (module-name opts.context opts.file-path)
141+
:useMetadata (cfg [:use_metadata])
142+
143+
;; Restart the REPL if...
144+
:fresh? (or ;; We eval an entire file or buffer.
145+
(= :file opts.origin) (= :buf opts.origin)
146+
147+
;; The user is evaluating the module form.
148+
(text.starts-with opts.code (.. "(module " (or opts.context ""))))})
149+
{: ok? : results} (eval! (.. opts.code "\n"))]
75150
(set opts.ok? ok?)
76151
(set opts.results results))))]
77152
(when (not (a.empty? out))
@@ -110,7 +185,11 @@
110185
(mapping.buf :n :FnlRunBufTests
111186
(cfg [:mapping :run_buf_tests]) *module-name* :run-buf-tests)
112187
(mapping.buf :n :FnlRunAllTests
113-
(cfg [:mapping :run_all_tests]) *module-name* :run-all-tests))
188+
(cfg [:mapping :run_all_tests]) *module-name* :run-all-tests)
189+
(mapping.buf :n :FnlResetREPL
190+
(cfg [:mapping :reset_repl]) *module-name* :reset-repl)
191+
(mapping.buf :n :FnlResetAllREPLs
192+
(cfg [:mapping :reset_all_repls]) *module-name* :reset-all-repls))
114193

115194
(defn value->completions [x]
116195
(when (= :table (type x))
@@ -132,15 +211,14 @@
132211

133212
(defn completions [opts]
134213
(let [code (when (not (str.blank? opts.prefix))
135-
(.. "((. (require :" *module-name* ") :value->completions) "
136-
(opts.prefix:gsub ".$" "") ")"))
214+
(let [prefix (string.gsub opts.prefix ".$" "")]
215+
(.. "((. (require :" *module-name* ") :value->completions) " prefix ")")))
137216
mods (value->completions package.loaded)
138-
locals (let [(ok? m) (and opts.context (pcall #(require opts.context)))]
217+
locals (let [(ok? m) (pcall #(require opts.context))]
139218
(if ok?
140219
(a.concat
220+
(value->completions m)
141221
(value->completions (a.get m :aniseed/locals))
142-
(value->completions (a.get-in m [:aniseed/local-fns :require]))
143-
(value->completions (a.get-in m [:aniseed/local-fns :autoload]))
144222
mods)
145223
mods))
146224
result-fn
@@ -155,12 +233,13 @@
155233
xs)
156234
locals)
157235
locals))))
158-
(_ ok?)
236+
(ok? err-or-res)
159237
(when code
160238
(pcall
161239
(fn []
162240
(eval-str
163-
{:context opts.context
241+
{:file-path opts.file-path
242+
:context opts.context
164243
:code code
165244
:passive? true
166245
:on-result-raw result-fn}))))]

fnl/conjure/eval.fnl

+2-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@
292292
(if (= :function (type (client.get :completions)))
293293
(client.call
294294
:completions
295-
(-> {:prefix prefix
295+
(-> {:file-path (extract.file-path)
296+
:prefix prefix
296297
:cb cb-wrap}
297298
(assoc-context)))
298299
(cb-wrap)))

fnl/conjure/extract.fnl

+4-6
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@
6464
flags (.. "Wnz" (if root? "r" ""))
6565
cursor-char (current-char)
6666

67-
skip-match?-viml "luaeval(\"require('conjure.extract')['skip-match?']()\")"
68-
6967
safe-start-char
7068
(if escape?
7169
(.. "\\" start-char)
@@ -79,16 +77,16 @@
7977
start (nvim.fn.searchpairpos
8078
safe-start-char "" safe-end-char
8179
(.. flags "b" (if (= cursor-char start-char) "c" ""))
82-
skip-match?-viml)
80+
skip-match?)
8381
end (nvim.fn.searchpairpos
8482
safe-start-char "" safe-end-char
8583
(.. flags (if (= cursor-char end-char) "c" ""))
86-
skip-match?-viml)]
84+
skip-match?)]
8785

8886
(when (and (not (nil-pos? start))
8987
(not (nil-pos? end)))
90-
{:range {:start (a.update start 2 a.dec)
91-
:end (a.update end 2 a.dec)}
88+
{:range {:start [(a.first start) (a.dec (a.second start))]
89+
:end [(a.first end) (a.dec (a.second end))]}
9290
:content (read-range start end)})))
9391

9492
(defn- range-distance [range]

fnl/conjure/fs.fnl

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(module conjure.fs
22
{autoload {nvim conjure.aniseed.nvim
33
a conjure.aniseed.core
4+
text conjure.text
45
str conjure.aniseed.string
56
afs conjure.aniseed.fs
67
config conjure.config}})
@@ -77,3 +78,15 @@
7778
(-> path
7879
(apply-path-subs (config.get-in [:path_subs]))
7980
(resolve-relative)))
81+
82+
(defn file-path->module-name [file-path]
83+
"Tries to match a file path up to an existing loaded Lua module."
84+
(when file-path
85+
(a.some
86+
(fn [mod-name]
87+
(let [mod-path (string.gsub mod-name "%." afs.path-sep)]
88+
(when (or
89+
(text.ends-with file-path (.. mod-path ".fnl"))
90+
(text.ends-with file-path (.. mod-path "/init.fnl")))
91+
mod-name)))
92+
(a.keys package.loaded))))

fnl/conjure/sponsors.fnl

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
"BerkeleyTrue"
99
"campbellr"
1010
"daveyarwood"
11+
"davidmh"
1112
"dharrigan"
1213
"emilaasa"
14+
"Fedreg"
1315
"frenchy64"
1416
"jkrasnay"
1517
"ketansrivastav"
1618
"lucaslollobrigida"
1719
"mamapitufo"
1820
"martinklepsch"
19-
"Olical"
20-
"pyrmont"
2121
"rafaeldelboni"
2222
"rbatista"
2323
"rgm"

fnl/conjure/text.fnl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(module conjure.text
2-
{:require {a conjure.aniseed.core
3-
str conjure.aniseed.string}})
2+
{require {a conjure.aniseed.core
3+
str conjure.aniseed.string}})
44

55
(defn trailing-newline? [s]
66
(= "\n" (string.sub s -1)))

0 commit comments

Comments
 (0)