Skip to content

Commit

Permalink
fix: clear fennels macros-loaded table when runing make compile
Browse files Browse the repository at this point in the history
Macro modules are retained by fennel in a macros-loaded table. If we
compile using a macro, then edit the macro, then recompile, we would end
up using the older in-memory macro and generate incorrect code.

By clearing the macros-loaded table before calling compile, we can
enforce that the latest macro code is loaded.

Currently this fix only applies to make, but could be extended to
diagnostics.

See #117.
  • Loading branch information
rktjmp committed Sep 4, 2023
1 parent de38c48 commit 9297ab3
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 189 deletions.
9 changes: 9 additions & 0 deletions fnl/hotpot/api/make.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@

(fn do-compile [compile-targets compiler-options root-dir]
(let [{: compile-file} (require :hotpot.lang.fennel.compiler)]
;; Issue https://github.com/rktjmp/hotpot.nvim/issues/117
;; Macro modules are retained in memory, so even if they're edited,
;; we compile with the older version and output incorrect code.
;; For now (?) we will force all macros to be reloaded each time make is
;; called to ensure they're reloaded.
(case package.loaded
{:hotpot.fennel fennel} (each [k _ (pairs fennel.macro-loaded)]
(tset fennel.macro-loaded k nil)))

(map (fn [{: src : dest}]
(let [tmp-path (.. (vim.fn.tempname) :.lua)
;; We compile via absolute paths since the cwd might not be
Expand Down
Loading

0 comments on commit 9297ab3

Please sign in to comment.