Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Olical committed Sep 29, 2021
2 parents 20f5a76 + ca55e4e commit 22f62e9
Show file tree
Hide file tree
Showing 74 changed files with 7,690 additions and 13,946 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: olical/aniseed-circleci:1.0.0
- image: olical/aniseed-circleci:1.1.0
steps:
- checkout
- run: make deps
Expand Down
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Use your favourite plugin manager, mine is https://github.com/junegunn/vim-plug[

[source,viml]
----
Plug 'Olical/conjure', {'tag': 'v4.23.0'}
Plug 'Olical/conjure', {'tag': 'v4.24.0'}
----

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.
Expand Down
14 changes: 14 additions & 0 deletions doc/conjure-client-fennel-aniseed.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,18 @@ All configuration can be set as described in |conjure-configuration|.
Run all loaded tests.
Default: `"ta"`

*g:conjure#client#fennel#aniseed#mapping#reset_repl*
`g:conjure#client#fennel#aniseed#mapping#reset_repl`
Reset the REPL for your current buffer. Use this if you need to
clear the local state in your REPL or you've somehow evaluated
unbalanced parenthesis.
Default: `"rr"`

*g:conjure#client#fennel#aniseed#mapping#reset_all_repls*
`g:conjure#client#fennel#aniseed#mapping#reset_all_repls`
Reset all currently loaded REPLs. Use this if you've maybe messed
up a few of your REPLs and you'd like to start fresh without
restarting Neovim.
Default: `"ra"`

vim:tw=78:sw=2:ts=2:ft=help:norl:et:listchars=
1 change: 1 addition & 0 deletions doc/conjure.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*conjure*
______ _ ~
/ ____/___ ____ (_)_ __________ ~
/ / / __ \/ __ \ / / / / / ___/ _ \~
Expand Down
7 changes: 4 additions & 3 deletions fnl/conjure/client/clojure/nrepl/action.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@
(a.nil? info)
(log.append ["; Nothing found via CIDER's info either"])

info.javadoc
(= :table (type info.javadoc))
(log.append (java-info->lines info))

info.doc
(= :string (type info.doc))
(log.append
(a.concat
[(.. "; " info.ns "/" info.name)
Expand Down Expand Up @@ -612,7 +612,8 @@
(when arglists
(table.concat arglists " "))]
" ")
:info info
:info (when (= :string (type info))
info)
:kind (when (not (a.empty? kind))
(string.upper
(string.sub kind 1 1)))})
Expand Down
121 changes: 100 additions & 21 deletions fnl/conjure/client/fennel/aniseed.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
view conjure.aniseed.view
client conjure.client
mapping conjure.mapping
fs conjure.fs
text conjure.text
log conjure.log
config conjure.config
Expand All @@ -19,7 +20,9 @@
{:fennel
{:aniseed
{:mapping {:run_buf_tests "tt"
:run_all_tests "ta"}
:run_all_tests "ta"
:reset_repl "rr"
:reset_all_repls "ra"}
:aniseed_module_prefix :conjure.aniseed.
:use_metadata true}}}})

Expand All @@ -38,14 +41,81 @@
(defn- anic [mod f-name ...]
((ani mod f-name) ...))

(defonce- repls {})

(defn reset-repl [filename]
(let [filename (or filename (fs.localise-path (extract.file-path)))]
(tset repls filename nil)
(log.append [(.. "; Reset REPL for " filename)] {:break? true})))

(defn reset-all-repls []
(a.run!
(fn [filename]
(tset repls filename nil))
(a.keys repls))
(log.append [(.. "; Reset all REPLs")] {:break? true}))

(def default-module-name "conjure.user")

(defn module-name [context file-path]
(if
context context
file-path (or (fs.file-path->module-name file-path) default-module-name)
default-module-name))

(defn repl [opts]
(let [filename (a.get opts :filename)]
(or ;; Reuse an existing REPL.
(and (not (a.get opts :fresh?)) (a.get repls filename))

;; Build a new REPL.
(let [;; Shared between the error-handler function (created at the same time as the REPL).
;; And each individual eval call. This allows us to capture errors from different call stacks.
ret {}

;; Set up the error-handler function on the creation of the REPL.
;; Will place any errors in the ret table.
_ (tset opts :error-handler
(fn [err]
(set ret.ok? false)
(set ret.results [err])))

;; Instantiate the raw REPL, we'll wrap this a little first though.
eval! (anic :eval :repl opts)

;; Build our REPL function.
repl (fn [code]
;; Reset the ret table before running anything.
(set ret.ok? nil)
(set ret.results nil)

;; Run the code, either capturing a result or an error.
;; If there's no error in ret we can place the results in the ret table.
(let [results (eval! code)]
(when (a.nil? ret.ok?)
(set ret.ok? true)
(set ret.results results))
;; Finally this good or bad result is returned.
ret))]

;; Set up the REPL in the module context.
(repl (.. "(module " (a.get opts :moduleName) ")"))

;; Store the REPL for future reuse.
(tset repls filename repl)

;; Return the new REPL!
repl))))

(defn display-result [opts]
(when opts
(let [{: ok? : results} opts
result-str (if ok?
(if (a.empty? results)
"nil"
(str.join "\n" (a.map view.serialise results)))
(a.first results))
result-str (or
(if ok?
(when (not (a.empty? results))
(str.join "\n" (a.map view.serialise results)))
(a.first results))
"nil")
result-lines (str.split result-str "\n")]
(when (not opts.passive?)
(log.append
Expand All @@ -60,18 +130,23 @@
(defn eval-str [opts]
((client.wrap
(fn []
(let [code (.. (.. "(module " (or opts.context "aniseed.user") ") ")
opts.code "\n")
out (anic :nu :with-out-str
(let [out (anic :nu :with-out-str
(fn []
(when (and (cfg [:use_metadata])
(not package.loaded.fennel))
(set package.loaded.fennel (anic :fennel :impl)))

(let [[ok? & results]
[(anic :eval :str code
{:filename opts.file-path
:useMetadata (cfg [:use_metadata])})]]
(let [eval! (repl {:filename opts.file-path
:moduleName (module-name opts.context opts.file-path)
:useMetadata (cfg [:use_metadata])

;; Restart the REPL if...
:fresh? (or ;; We eval an entire file or buffer.
(= :file opts.origin) (= :buf opts.origin)

;; The user is evaluating the module form.
(text.starts-with opts.code (.. "(module " (or opts.context ""))))})
{: ok? : results} (eval! (.. opts.code "\n"))]
(set opts.ok? ok?)
(set opts.results results))))]
(when (not (a.empty? out))
Expand Down Expand Up @@ -110,7 +185,11 @@
(mapping.buf :n :FnlRunBufTests
(cfg [:mapping :run_buf_tests]) *module-name* :run-buf-tests)
(mapping.buf :n :FnlRunAllTests
(cfg [:mapping :run_all_tests]) *module-name* :run-all-tests))
(cfg [:mapping :run_all_tests]) *module-name* :run-all-tests)
(mapping.buf :n :FnlResetREPL
(cfg [:mapping :reset_repl]) *module-name* :reset-repl)
(mapping.buf :n :FnlResetAllREPLs
(cfg [:mapping :reset_all_repls]) *module-name* :reset-all-repls))

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

(defn completions [opts]
(let [code (when (not (str.blank? opts.prefix))
(.. "((. (require :" *module-name* ") :value->completions) "
(opts.prefix:gsub ".$" "") ")"))
(let [prefix (string.gsub opts.prefix ".$" "")]
(.. "((. (require :" *module-name* ") :value->completions) " prefix ")")))
mods (value->completions package.loaded)
locals (let [(ok? m) (and opts.context (pcall #(require opts.context)))]
locals (let [(ok? m) (pcall #(require opts.context))]
(if ok?
(a.concat
(value->completions m)
(value->completions (a.get m :aniseed/locals))
(value->completions (a.get-in m [:aniseed/local-fns :require]))
(value->completions (a.get-in m [:aniseed/local-fns :autoload]))
mods)
mods))
result-fn
Expand All @@ -155,12 +233,13 @@
xs)
locals)
locals))))
(_ ok?)
(ok? err-or-res)
(when code
(pcall
(fn []
(eval-str
{:context opts.context
{:file-path opts.file-path
:context opts.context
:code code
:passive? true
:on-result-raw result-fn}))))]
Expand Down
3 changes: 2 additions & 1 deletion fnl/conjure/eval.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@
(if (= :function (type (client.get :completions)))
(client.call
:completions
(-> {:prefix prefix
(-> {:file-path (extract.file-path)
:prefix prefix
:cb cb-wrap}
(assoc-context)))
(cb-wrap)))
Expand Down
10 changes: 4 additions & 6 deletions fnl/conjure/extract.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
flags (.. "Wnz" (if root? "r" ""))
cursor-char (current-char)

skip-match?-viml "luaeval(\"require('conjure.extract')['skip-match?']()\")"

safe-start-char
(if escape?
(.. "\\" start-char)
Expand All @@ -79,16 +77,16 @@
start (nvim.fn.searchpairpos
safe-start-char "" safe-end-char
(.. flags "b" (if (= cursor-char start-char) "c" ""))
skip-match?-viml)
skip-match?)
end (nvim.fn.searchpairpos
safe-start-char "" safe-end-char
(.. flags (if (= cursor-char end-char) "c" ""))
skip-match?-viml)]
skip-match?)]

(when (and (not (nil-pos? start))
(not (nil-pos? end)))
{:range {:start (a.update start 2 a.dec)
:end (a.update end 2 a.dec)}
{:range {:start [(a.first start) (a.dec (a.second start))]
:end [(a.first end) (a.dec (a.second end))]}
:content (read-range start end)})))

(defn- range-distance [range]
Expand Down
13 changes: 13 additions & 0 deletions fnl/conjure/fs.fnl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(module conjure.fs
{autoload {nvim conjure.aniseed.nvim
a conjure.aniseed.core
text conjure.text
str conjure.aniseed.string
afs conjure.aniseed.fs
config conjure.config}})
Expand Down Expand Up @@ -77,3 +78,15 @@
(-> path
(apply-path-subs (config.get-in [:path_subs]))
(resolve-relative)))

(defn file-path->module-name [file-path]
"Tries to match a file path up to an existing loaded Lua module."
(when file-path
(a.some
(fn [mod-name]
(let [mod-path (string.gsub mod-name "%." afs.path-sep)]
(when (or
(text.ends-with file-path (.. mod-path ".fnl"))
(text.ends-with file-path (.. mod-path "/init.fnl")))
mod-name)))
(a.keys package.loaded))))
4 changes: 2 additions & 2 deletions fnl/conjure/sponsors.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"BerkeleyTrue"
"campbellr"
"daveyarwood"
"davidmh"
"dharrigan"
"emilaasa"
"Fedreg"
"frenchy64"
"jkrasnay"
"ketansrivastav"
"lucaslollobrigida"
"mamapitufo"
"martinklepsch"
"Olical"
"pyrmont"
"rafaeldelboni"
"rbatista"
"rgm"
Expand Down
4 changes: 2 additions & 2 deletions fnl/conjure/text.fnl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(module conjure.text
{:require {a conjure.aniseed.core
str conjure.aniseed.string}})
{require {a conjure.aniseed.core
str conjure.aniseed.string}})

(defn trailing-newline? [s]
(= "\n" (string.sub s -1)))
Expand Down
Loading

0 comments on commit 22f62e9

Please sign in to comment.