From cd9821cd80e7e4db8bbed388cbaf17473cd54ba3 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Fri, 29 Aug 2025 16:09:27 -0500 Subject: [PATCH] fix fennel-ls#81 --- src/fennel-ls/compiler.fnl | 3 +++ test/completion.fnl | 2 +- test/diagnostic.fnl | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/fennel-ls/compiler.fnl b/src/fennel-ls/compiler.fnl index 621687c..0785f68 100644 --- a/src/fennel-ls/compiler.fnl +++ b/src/fennel-ls/compiler.fnl @@ -24,6 +24,9 @@ identifiers are declared / referenced in which places." (icollect [k (pairs compiler-env)] k))) (set compiler-env._G._FENNEL_LS true) +;; FIXME: this is a workaround for https://dev.fennel-lang.org/ticket/51#ticket +(set-forcibly! compiler-env (collect [k v ((. (getmetatable compiler-env) :__pairs) compiler-env)] k v)) + (local nil* (sym :nil)) (fn scope? [candidate] diff --git a/test/completion.fnl b/test/completion.fnl index 680b950..4e82574 100644 --- a/test/completion.fnl +++ b/test/completion.fnl @@ -274,7 +274,7 @@ (fn test-compiler-env [] (check ";; fennel-ls: macro-file\n(" - [:sym :sym? :list :quote :icollect :math] + [:sym :sym? :list :quote :icollect :math :ipairs] [:os]) ;; TODO #73 ; (check "(macro foo [] (|" diff --git a/test/diagnostic.fnl b/test/diagnostic.fnl index 636e396..e0897e6 100644 --- a/test/diagnostic.fnl +++ b/test/diagnostic.fnl @@ -168,12 +168,32 @@ [{:message "unknown field: math.atan2"}] {:lua-version "lua5.3"})) +(fn test-macro-environment [] + (check {:main.fnl "(macro not-any [subject & vals] + \"Returns `true` if `subject` is not equal to any of the remaining values.\" + (let [conds# (icollect [_ v# (ipairs vals)] + `(not= ,subject ,v#))] + `(and ,(unpack conds#))))"} + [] + [{}]) + (check {:main.fnl ";; fennel-ls: macro-file + (fn not-any [subject & vals] + \"Returns `true` if `subject` is not equal to any of the remaining values.\" + (let [conds# (icollect [_ v# (ipairs vals)] + `(not= ,subject ,v#))] + `(and ,(unpack conds#)))) + {: not-any}"} + [] + [{}]) + nil) + (fn test-warnings [] (check "(print \"hello\"table)" [{:message "expected whitespace before token"}] [])) {: test-lua-versions + : test-macro-environment : test-compile-error : test-parse-error : test-macro-error