"A collection of macros for providing fennel-ls context to tables
with metatables.

Add a type-def field to the table returned by a module that creates
a new table with a metatable.

Use local-flt in place of local when creating or accessing a new table.
Alternativly, you can use flt if you want to wrap a return value without
asigning it to a local (e.g. when using let).

``` fennel
;; module.fnl

(fn add [self b]
  (local new-value (+ self.value b))
  (set self.value new-value)
  self)

(local mt {:__index {: add}})

(fn new [value]
  (local tab {: value})
  (setmetatable tab mt))

{: new :type-def mt}
```

``` fennel
(import-macros {: local-flt : flt} :local-flt)
(local {: new} (require :module))
(local-flt example :module (new 11))
;; you should now get completion if you are running fennel ls
(example:add 11)

(local example-collection [])
(table.insert example-collection example)
(let [example2 (flt :module (. example-collection 1))]
  ;; you should also get completion here!
  (example2:add 11))
```
"

;; Set true if you want to always expand macros assuming you are in a FENNEL_LS
;; environment. Helpful when debugging compilation.
(local forced false)

(fn local-flt [key *module val]
  "local-flt acts as a normal local unless in the FENNEL_LS environemnt.
When in the FENNEL_LS environemnt it looks for the type-def returned in the
module table referenced in the second arg. This type-def should be the
metatable used for the tables geneated by the module.

key: the local value being asinged
*module: the location of the module with the associated type-def
value: the value being asigned"
  `(local ,key
          ,(if (or forced _G._FENNEL_LS)
               (match *module
                 :string ""
                 v `(. (require ,v) :type-def :__index)
                 _ {})
               val)))

(fn flt [*module val]
  "flt lets you wrap a return value in such a way that FENNEL_LS can provide
completion candidates for its values. In an environmenbt that is not FENNEL_LS
this is a direct pass through.

*module: the location of the module with the associated type-def
value: the value being asigned"
  (if (or forced _G._FENNEL_LS)
      (match *module
        :string ""
        v `(. (require ,v) :type-def :__index)
        _ {})
      val))

{: local-flt : flt}

Generated by alexjgriffith using scpaste at Wed Jan 7 12:10:34 2026. EST. (original)