Do not warn on fennel rest in function
I kept the test from Tibor Classen's patch, but the code is fixed by preventing & from ever being a definition, instead of ignoring it only in the diagnostic. Co-authored-by: Tibor Claassen <tc@codebeige.net>
This commit is contained in:
parent
824525573a
commit
27d1df23eb
@ -184,7 +184,8 @@ later by fennel-ls.language to answer requests from the client."
|
|||||||
(where [_fn _name args] (fennel.sequence? args)) args
|
(where [_fn _name args] (fennel.sequence? args)) args
|
||||||
_ []))
|
_ []))
|
||||||
(each [_ argument (ipairs args)]
|
(each [_ argument (ipairs args)]
|
||||||
(define (sym :nil) argument scope))) ;; TODO for now, function arguments are set to nil
|
(if (not (sym? argument :&))
|
||||||
|
(define (sym :nil) argument scope)))) ;; TODO for now, function arguments are set to nil
|
||||||
|
|
||||||
(λ define-function [ast scope]
|
(λ define-function [ast scope]
|
||||||
;; handle the definitions of a function
|
;; handle the definitions of a function
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
diagnostic
|
diagnostic
|
||||||
(match responses
|
(match responses
|
||||||
[{:params {: diagnostics}}]
|
[{:params {: diagnostics}}]
|
||||||
(is (find [i v (ipairs diagnostics)]
|
(is (find [_ v (ipairs diagnostics)]
|
||||||
(match v
|
(match v
|
||||||
{:message "tried to reference a special form without calling it"
|
{:message "tried to reference a special form without calling it"
|
||||||
:range {:start {:character 4 :line 0}
|
:range {:start {:character 4 :line 0}
|
||||||
@ -41,7 +41,7 @@
|
|||||||
diagnostic
|
diagnostic
|
||||||
(match responses
|
(match responses
|
||||||
[{:params {: diagnostics}}]
|
[{:params {: diagnostics}}]
|
||||||
(is (find [i v (ipairs diagnostics)]
|
(is (find [_ v (ipairs diagnostics)]
|
||||||
(match v
|
(match v
|
||||||
{:message "expected whitespace before opening delimiter ("
|
{:message "expected whitespace before opening delimiter ("
|
||||||
:range {:start {:character 17 :line 0}
|
:range {:start {:character 17 :line 0}
|
||||||
@ -72,7 +72,7 @@
|
|||||||
responses (self:open-file! filename "(local x 10)")]
|
responses (self:open-file! filename "(local x 10)")]
|
||||||
(match responses
|
(match responses
|
||||||
[{:params {: diagnostics}}]
|
[{:params {: diagnostics}}]
|
||||||
(is (find [i v (ipairs diagnostics)]
|
(is (find [_ v (ipairs diagnostics)]
|
||||||
(match v
|
(match v
|
||||||
{:message "unused definition: x"
|
{:message "unused definition: x"
|
||||||
:range {:start {:character 7 :line 0}
|
:range {:start {:character 7 :line 0}
|
||||||
@ -86,7 +86,7 @@
|
|||||||
responses (self:open-file! filename "(fn x [])")]
|
responses (self:open-file! filename "(fn x [])")]
|
||||||
(match responses
|
(match responses
|
||||||
[{:params {: diagnostics}}]
|
[{:params {: diagnostics}}]
|
||||||
(is (find [i v (ipairs diagnostics)]
|
(is (find [_ v (ipairs diagnostics)]
|
||||||
(match v
|
(match v
|
||||||
{:message "unused definition: x"
|
{:message "unused definition: x"
|
||||||
:range {:start {:character 4 :line 0}
|
:range {:start {:character 4 :line 0}
|
||||||
@ -105,7 +105,7 @@
|
|||||||
responses (self:open-file! filename "(var x 1) (set x 2) (set [x] [3])")]
|
responses (self:open-file! filename "(var x 1) (set x 2) (set [x] [3])")]
|
||||||
(match responses
|
(match responses
|
||||||
[{:params {: diagnostics}}]
|
[{:params {: diagnostics}}]
|
||||||
(is (find [i v (ipairs diagnostics)]
|
(is (find [_ v (ipairs diagnostics)]
|
||||||
(match v
|
(match v
|
||||||
{:message "unused definition: x"
|
{:message "unused definition: x"
|
||||||
:range {:start {:character 5 :line 0}
|
:range {:start {:character 5 :line 0}
|
||||||
@ -114,17 +114,27 @@
|
|||||||
"not found")
|
"not found")
|
||||||
_ (error "did not match"))))
|
_ (error "did not match"))))
|
||||||
|
|
||||||
(it "does not warn in this particular code"
|
(it "does not warn on ampersand in destructuring"
|
||||||
(let [self (create-client)
|
(let [self (create-client)
|
||||||
responses (self:open-file! filename "(let [[x & y] [1 2 3]] (print x (. y 1) (. y 2)))")]
|
responses (self:open-file! filename "(let [[x & y] [1 2 3]] (print x (. y 1) (. y 2)))")]
|
||||||
(match responses
|
(match responses
|
||||||
[{:params {: diagnostics}}]
|
[{:params {: diagnostics}}]
|
||||||
(is.nil (find [i v (ipairs diagnostics)]
|
(is.nil (find [_ v (ipairs diagnostics)]
|
||||||
(match v
|
(match v
|
||||||
{:message "unused definition: &"}
|
{:message "unused definition: &"}
|
||||||
v))
|
v))
|
||||||
"not found")
|
"not found")
|
||||||
_ (error "did not match")))))
|
_ (error "did not match"))))
|
||||||
|
|
||||||
|
(it "does not warn on ampersand in function parameters"
|
||||||
|
(let [self (create-client)
|
||||||
|
responses (self:open-file! filename "(fn [x & more] (print x more))")]
|
||||||
|
(match responses
|
||||||
|
[{:params {: diagnostics}}]
|
||||||
|
(is.nil (find [_ v (ipairs diagnostics)]
|
||||||
|
(match v
|
||||||
|
{:message "unused definition: &"}
|
||||||
|
v)))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user