From bf17771babf70ca5941deb9e0cbff86a9b7c1ca4 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Tue, 7 Oct 2025 20:10:11 -0700 Subject: [PATCH] Enable legacy-multival lint on fennel-ls itself and fix self-lints. --- flsproject.fnl | 3 ++- src/fennel-ls/analyzer.fnl | 4 ++-- src/fennel-ls/compiler.fnl | 6 +++--- src/fennel-ls/completion.fnl | 4 ++-- src/fennel-ls/dispatch.fnl | 18 +++++++++--------- src/fennel-ls/json-rpc.fnl | 9 ++++----- src/fennel-ls/message.fnl | 6 +++--- src/fennel-ls/utils.fnl | 6 +++--- test/init.fnl | 7 +++---- test/misc.fnl | 4 ++-- test/utils/init.fnl | 14 +++++++------- 11 files changed, 40 insertions(+), 41 deletions(-) diff --git a/flsproject.fnl b/flsproject.fnl index 38fb917..4c5bc5d 100644 --- a/flsproject.fnl +++ b/flsproject.fnl @@ -1,3 +1,4 @@ {:lua-version "intersection" - :lints {:not-enough-arguments true} + :lints {:not-enough-arguments true + :legacy-multival true} :fennel-path "./?.fnl;./?/init.fnl;src/?.fnl;src/?/init.fnl;deps/?.fnl;deps/?/init.fnl"} diff --git a/src/fennel-ls/analyzer.fnl b/src/fennel-ls/analyzer.fnl index d9ca89c..ff9f8f3 100644 --- a/src/fennel-ls/analyzer.fnl +++ b/src/fennel-ls/analyzer.fnl @@ -281,13 +281,13 @@ initialization-opts: {:stack ?list[ast] (table.insert parents ast) (if (or (sequence? ast) (list? ast)) - (accumulate [(result _parent) nil + (accumulate [result nil _ child (ipairs ast) &until result] (if (contains? child byte) (recurse child))) (and (not (sym? ast)) (not (varg? ast))) - (accumulate [(result _parent) nil + (accumulate [result nil key value (pairs ast) &until result] (if (contains? key byte) diff --git a/src/fennel-ls/compiler.fnl b/src/fennel-ls/compiler.fnl index 64b86fd..eefa0aa 100644 --- a/src/fennel-ls/compiler.fnl +++ b/src/fennel-ls/compiler.fnl @@ -381,9 +381,9 @@ identifiers are declared / referenced in which places." : compiler-env : warn} filter-errors (fn _filter-errors [component ...] - (case ... - (true ?item1 ?item2) (values ?item1 ?item2) - (where (or (nil err) (false err)) (not (err:find "^[^\n]-__NOT_AN_ERROR\n"))) + (case [...] + [true ?item1 ?item2] (values ?item1 ?item2) + (where (or [nil err] [false err]) (not (err:find "^[^\n]-__NOT_AN_ERROR\n"))) (if (os.getenv :DEV) (error (.. "\nYou have crashed fennel-ls (or the fennel " component ") with the following message\n:" err "\n\n^^^ the error message above here is the root problem\n\n")) diff --git a/src/fennel-ls/completion.fnl b/src/fennel-ls/completion.fnl index 60486eb..8129510 100644 --- a/src/fennel-ls/completion.fnl +++ b/src/fennel-ls/completion.fnl @@ -50,7 +50,7 @@ we support completionItem/resolve." file {:text (.. (file.text:sub 1 (- byte 1)) "|" (file.text:sub byte)) :uri file.uri} _ (compiler.compile server file) ;; find what ast objects are under the cursor - (symbol parents) (analyzer.find-symbol server file byte) + [symbol parents] [(analyzer.find-symbol server file byte)] ;; check what context I'm in in-call-position? (or (and (fennel.list? (. parents 1)) (= symbol (. parents 1 1))) @@ -161,7 +161,7 @@ we support completionItem/resolve." (fn completionItem/resolve [server _send completion-item] (let [{: uri : byte} completion-item.data file (files.get-by-uri server uri) - (_symbol parents) (analyzer.find-symbol server file byte) + [_symbol parents] [(analyzer.find-symbol server file byte)] scope (or (. file.scopes _symbol) (accumulate [?find nil _ parent (ipairs parents) &until ?find] (. file.scopes parent)) diff --git a/src/fennel-ls/dispatch.fnl b/src/fennel-ls/dispatch.fnl index ced13d4..6364090 100644 --- a/src/fennel-ls/dispatch.fnl +++ b/src/fennel-ls/dispatch.fnl @@ -14,9 +14,9 @@ In general, this involves: ;; The return value of the request is sent back to the server. (case (. handlers.requests method) callback - (case (callback server send ?params) - (nil err) (send (message.create-error :InternalError err id)) - ?response (send (message.create-response id ?response))) + (case [(callback server send ?params)] + [nil err] (send (message.create-error :InternalError err id)) + [?response] (send (message.create-response id ?response))) nil (send (message.create-error @@ -48,16 +48,16 @@ Takes: * `send`, which is a callback for sending responses, and * `msgs`, which is a list of incoming messages." (each [_ msg (ipairs batch)] - (case (values msg (type msg)) - {:jsonrpc "2.0" : id : method :params ?params} + (case [msg (type msg)] + [{:jsonrpc "2.0" : id : method :params ?params}] (handle-request server send id method ?params) - {:jsonrpc "2.0" : method :params ?params} + [{:jsonrpc "2.0" : method :params ?params}] (handle-notification server send method ?params) - {:jsonrpc "2.0" : id : result} + [{:jsonrpc "2.0" : id : result}] (handle-response server send id result) - {:jsonrpc "2.0" : id :error err} + [{:jsonrpc "2.0" : id :error err}] (handle-bad-response server send id err) - (str :string) + [str :string] (send (message.create-error :ParseError str)) _ (send (message.create-error :BadMessage nil msg.id))) diff --git a/src/fennel-ls/json-rpc.fnl b/src/fennel-ls/json-rpc.fnl index 086c1b7..bb5c049 100644 --- a/src/fennel-ls/json-rpc.fnl +++ b/src/fennel-ls/json-rpc.fnl @@ -24,7 +24,7 @@ on the empty table to tell dkjson to serialize as {}." nil nil ;; I've hit end of stream, return nil instead of a header line (case (line:match "^(.-)\r?$") ;; strip trailing \r "" header ;; base case. empty line marks end of header - line (let [(k v) (line:match "^(.-): (.-)$")] + line (let [[k v] [(line:match "^(.-): (.-)$")]] (if (not (and k v)) (error (.. "fennel-ls encountered a malformed json-rpc header: \"" line "\""))) (tset header k v) @@ -49,10 +49,9 @@ If there aren't enough bytes, return nil" (λ read [in] "Reads and parses a JSON-RPC message from the input stream Returns a table with the message if it succeeded, or a string with the parse error if it fails." - (let [(?result _?err-pos ?err) - (-?>> (read-header in) - (read-content in) - decode)] + (let [[?result _?err-pos ?err] [(-?>> (read-header in) + (read-content in) + decode)]] (or ?result ?err))) (λ write [out msg] diff --git a/src/fennel-ls/message.fnl b/src/fennel-ls/message.fnl index 03cabd0..3b160c2 100644 --- a/src/fennel-ls/message.fnl +++ b/src/fennel-ls/message.fnl @@ -95,9 +95,9 @@ LSP json objects." (λ multisym->range [server file ast n] (let [spl (utils.multi-sym-split ast)] - (case (values (utils.get-ast-info ast :bytestart) - (utils.get-ast-info ast :byteend)) - (bytestart byteend) + (case [(utils.get-ast-info ast :bytestart) + (utils.get-ast-info ast :byteend)] + [bytestart byteend] (let [bytesubstart (faccumulate [b bytestart i 1 (- n 1)] (+ b (length (. spl i)) 1)) diff --git a/src/fennel-ls/utils.fnl b/src/fennel-ls/utils.fnl index 2bdfb1c..95e7d3b 100644 --- a/src/fennel-ls/utils.fnl +++ b/src/fennel-ls/utils.fnl @@ -39,7 +39,7 @@ These functions are all pure functions, which makes me happy." (var o8 0) (var o16 0) (while (< o8 unit8) - (let [(a8 a16) (utf (str:byte (+ 1 o8)))] + (let [[a8 a16] [(utf (str:byte (+ 1 o8)))]] (set o8 (+ o8 a8)) (set o16 (+ o16 a16)))) (if (= o8 unit8) @@ -52,7 +52,7 @@ These functions are all pure functions, which makes me happy." (var o8 0) (var o16 0) (while (< o16 unit16) - (let [(a8 a16) (utf (str:byte (+ 1 o8)))] + (let [[a8 a16] [(utf (str:byte (+ 1 o8)))]] (set o8 (+ o8 a8)) (set o16 (+ o16 a16)))) (if (= o16 unit16) @@ -218,7 +218,7 @@ WARNING: this is only used in the test code, not in the real language server" (not (str:find "[^!#$%&*+/0-9<=>?A-Z\\^_a-z|\128-\255-]")))) (fn find [t x ?k] - (match (next t ?k) (k x) k (k y_) (find t x k))) + (match [(next t ?k)] [k x] k [k y_] (find t x k))) {: version : uri->path diff --git a/test/init.fnl b/test/init.fnl index d8b7540..bef4196 100644 --- a/test/init.fnl +++ b/test/init.fnl @@ -4,10 +4,9 @@ (set debug.getinfo (or fennel.getinfo debug.getinfo)) (set debug.traceback (or fennel.traceback debug.traceback)) -(case (string.match (or (os.getenv "FAITH_TEST") "") - "([^ ]+) ?([^ ]*)") - (module "") (faith.run [module]) - (module function) (do +(case [(string.match (or (os.getenv "FAITH_TEST") "") "([^ ]+) ?([^ ]*)")] + [module ""] (faith.run [module]) + [module function] (do (tset package.loaded module {function (. (require module) function)}) (faith.run [module])) diff --git a/test/misc.fnl b/test/misc.fnl index a19fbfd..f40c003 100644 --- a/test/misc.fnl +++ b/test/misc.fnl @@ -19,7 +19,7 @@ (fn test-find-symbol [] (let [{: server : uri} (create-client "(match [1 2 4] [1 2 sym-one] sym-one)") file (. server.files uri) - (symbol parents) (analyzer.find-symbol server file 23)] + [symbol parents] [(analyzer.find-symbol server file 23)]] (faith.= symbol (fennel.sym :sym-one)) (faith.= "[[1 2 sym-one] (match [1 2 4] [1 2 sym-one] sym-one) [(match [1 2 4] [1 2 sym-one] sym-one)]]" @@ -28,7 +28,7 @@ (let [{: server : uri} (create-client "(match [1 2 4] [1 2 sym-one] sym-one)") file (. server.files uri) - (symbol parents) (analyzer.find-symbol server file 18)] + [symbol parents] [(analyzer.find-symbol server file 18)]] (faith.= symbol nil) (faith.= "[[1 2 sym-one] (match [1 2 4] [1 2 sym-one] sym-one) [(match [1 2 4] [1 2 sym-one] sym-one)]]" diff --git a/test/utils/init.fnl b/test/utils/init.fnl index cf27e62..3e58270 100644 --- a/test/utils/init.fnl +++ b/test/utils/init.fnl @@ -18,10 +18,10 @@ encoding (or ?encoding default-encoding)] (while (case - (case (values (text:find "|") (text:find "==")) - (where (| ==) (< | ==)) [| "|"] - (_ ==) [== "=="] - (| _) [| "|"]) + (case [(text:find "|") (text:find "==")] + (where [| ==] (< | ==)) [| "|"] + [_ ==] [== "=="] + [| _] [| "|"]) [i "|"] (do (set text (.. (text:sub 1 (- i 1)) (text:sub (+ i 1)))) @@ -44,9 +44,9 @@ (fn create-client [file-contents ?opts ?config] ;; TODO big function, split up (let [opts (or ?opts {}) - (provide-root-uri file-contents) (if (= (type file-contents) :table) - (values true file-contents) - (values false {:main.fnl file-contents})) + [provide-root-uri file-contents] (if (= (type file-contents) :table) + [true file-contents] + [false {:main.fnl file-contents}]) server {:preload (if provide-root-uri {})} client (doto {: server :prev-id 1}