Enable legacy-multival lint on fennel-ls itself and fix self-lints.

This commit is contained in:
Phil Hagelberg 2025-10-07 20:10:11 -07:00
parent 2b2c31c577
commit bf17771bab
11 changed files with 40 additions and 41 deletions

View File

@ -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"}

View File

@ -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)

View File

@ -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"))

View File

@ -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))

View File

@ -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)))

View File

@ -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]

View File

@ -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))

View File

@ -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

View File

@ -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]))

View File

@ -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)]]"

View File

@ -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}