-
-
Notifications
You must be signed in to change notification settings - Fork 146
nfnl Conversion Guide
@Olical suggested these guidelines to follow when converting Conjure source files from Aniseed to nfnl.
See the nfnl API docs for the equivalent Aniseed functions.
- Keep the use of Aniseed modules in the code for now.
- Optionally, migrate to nfnl versions of the modules like str and core. If there are any issues then just
stick with Aniseed for now.
- Can replace
conjure.aniseed.corewithnfnl.core(see nfnl.core functions). - Can replace
conjure.aniseed.stringwithnfnl.string(see nfnl.string functions).
- Can replace
- This first pass aims to remove Aniseed for compiling Fennel into Lua. Completely dropping Aniseed will take more time to complete.
- Dropping Aniseed will require migrating to Neovim's built-in functions that were integrated from nvim.lua in 2019.
aniseed.nvimprovides thenvim.luafunctions by being a wrapper over them.
- Dropping Aniseed will require migrating to Neovim's built-in functions that were integrated from nvim.lua in 2019.
-
Replace
modulewith calls to nfnl's autoload to load deps.Legacy | Busted -------------------------------------------+------------------------------------------------ (module conjure.buffer | (local {: autoload} (require :nfnl.module)) {autoload {nvim conjure.aniseed.nvim | (local nvim (autoload :conjure.aniseed.nvim)) a conjure.aniseed.core | (local a (autoload :nfnl.core)) str conjure.aniseed.string | (local str (autoload :nfnl.string)) text conjure.text}}) | (local text (autoload :conjure.text)) -
Remove
import-macrosstatements.(import-macros {: module : def : defn : defonce : def- : defn- : defonce- : wrap-last-expr : wrap-module-body : deftest} :nfnl.macros.aniseed) -
Replace
defnwithfn.Legacy | Busted -------------------------------------------+------------------------------------------------ (defn form [opts] | (fn form [opts] -
Replace
defn-withfn(private function; don't export).Legacy | Busted -------------------------------------------+------------------------------------------------ (defn- getpos [expr] | (fn getpos [expr] -
Replace
defoncewithlocal. -
Replace
def-withlocal(private name; don't export).Legacy | Busted -------------------------------------------+------------------------------------------------ (defonce conjure-source-directory | (local conjure-source-directory (def- cats-and-dogs | (local cats-and-dogs -
Optional: Replace
if-letwith aletand anif.nfnl.macrosprovides the equivalent.Legacy | Busted -------------------------------------------+------------------------------------------------ (if-let [node (ts.get-leaf)] | (let [node (ts.get-leaf)] | (if node {:range (ts.range node) | {:range (ts.range node) :content (ts.node->str node)} | :content (ts.node->str node)} {:range nil | {:range nil :content nil}) | :content nil})) -
Remove
*module*at bottom of the file.Legacy | Busted -------------------------------------------+------------------------------------------------ *module* | -
Add a table at the bottom of the file to export anything public.
Legacy | Busted -------------------------------------------+------------------------------------------------ | {: form | : prompt | : prompt-char}-
defn-declares a private function so don't include them in the table.
-
-
Create the equivalent of tests for
aniseed-legacy-tests/infnl/conjure-spec/.Legacy | Busted -------------------------------------------+------------------------------------------------ `<module>-test.fnl` | `<module>_spec.fnl` -
Remove
moduleand replace withrequires forplenaryandbusted.Legacy | Busted ------------------------------------------------+------------------------------------------------ | (local {: describe : it} (require :plenary.busted)) | (local assert (require :luassert.assert)) | (module conjure.fs-test | (describe "fs" | (fn [] | (describe ...) ;; a test {require {fs conjure.fs | (local fs (require :conjure.fs)) nvim conjure.aniseed.nvim}}) | (local nvim (require :conjure.aniseed.nvim)) -
Replace
deftestwithdescribe. -
Replace
t.=withassert.are.equals. -
Replace
t.pr=withassert.same.Legacy | Busted ---------------------------------------------------------+------------------------------------------------ (deftest config-dir | (describe "config-dir" (t.= "/home/conjure/.config/conjure" (fs.config-dir)) | (assert.are.equals "/home/conjure/.config/conjure" | (fs.config-dir)) (t.pr= [] (fs.split-path "")) | (assert.same [] (fs.split-path "")))
-
Run
scripts/setup-test-depsto set up a hidden directory,.test-config/which acts as the test environment. -
Run
scripts/testto execute the new tests under thelua/conjure-spec/directory. -
If your Neovim is set up with Conjure, Plenary, Aniseed, and nfnl, you can run the busted tests from the Neovim command line with:
:PlenaryBustedDirectory lua/conjure-specOr run a single test file with:
:PlenaryBustedFile lua/conjure-spec/fs_spec.lua