From f68d8ba6fc85a45c03b18c76048b7f8460ed06a4 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Sun, 6 Apr 2025 16:14:42 -0500 Subject: [PATCH] compiler warnings --- src/fennel-ls/compiler.fnl | 9 +++++++++ test/diagnostic.fnl | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/fennel-ls/compiler.fnl b/src/fennel-ls/compiler.fnl index 13fb0e9..8aba772 100644 --- a/src/fennel-ls/compiler.fnl +++ b/src/fennel-ls/compiler.fnl @@ -326,6 +326,14 @@ identifiers are declared / referenced in which places." (call-me-to-reset-the-compiler) (error "__NOT_AN_ERROR")))) + (λ warn [msg ?ast _file ?line] + (let [range (or (message.ast->range server file ?ast) (line+byte->range server file (or ?line 1) 0))] + (table.insert diagnostics + {:range range + :message msg + :severity message.severity.WARN + :code :compiler-warning}))) + (local allowed-globals (docs.get-all-globals server)) (icollect [extra-global (server.configuration.extra-globals:gmatch "[^ ]+") &into allowed-globals] @@ -358,6 +366,7 @@ identifiers are declared / referenced in which places." :allowedGlobals allowed-globals :useMetadata true :requireAsInclude false + : warn : scope} filter-errors (fn _filter-errors [component ...] (case ... diff --git a/test/diagnostic.fnl b/test/diagnostic.fnl index 77cfe8d..60a9cae 100644 --- a/test/diagnostic.fnl +++ b/test/diagnostic.fnl @@ -167,8 +167,14 @@ [{:message "unknown field: math.atan2"}] {:lua-version "lua5.3"})) +(fn test-warnings [] + (check "(print \"hello\"table)" + [{:message "expected whitespace before token"}] + [])) + {: test-lua-versions : test-compile-error : test-parse-error : test-macro-error - : test-multiple-errors} + : test-multiple-errors + : test-warnings}