fix issue with duplicate errors

fixes #75
This commit is contained in:
XeroOl 2025-08-08 01:12:57 -05:00
parent fce339f506
commit bf3f353b8d
3 changed files with 31 additions and 4 deletions

View File

@ -137,9 +137,12 @@ we support completionItem/resolve."
(fn binding-completions []
"completions when you're writing a destructure pattern. We suggest identifiers which are unknown"
(each [_ {: message} (ipairs file.compile-errors)]
(case (message:match "unknown identifier: ([a-zA-Z0-9_-]+)")
identifier (add-completion! identifier {} :Variable))))
(let [seen {}]
(each [_ {: message} (ipairs file.compile-errors)]
(case (message:match "unknown identifier: ([a-zA-Z0-9_-]+)")
(where identifier (not (. seen identifier)))
(do (tset seen identifier true)
(add-completion! identifier {} :Variable))))))
(when symbol
(if (. file.definitions symbol)

View File

@ -116,6 +116,13 @@
(+ number-of-x 1)
number-of-x))))
[])
(check "(let [f| 10] foo foo foo"
(fn [completions]
(faith.= 1 (accumulate [number-of-foo 0 _ completion (ipairs completions.items)]
(if (= completion.label :foo)
(+ number-of-foo 1)
number-of-foo))))
[])
;; completions of fields (nested)
(check "(local x {:y {:z {:a {:b 1}}}}) ; deep tables
(local m {}) ; split modules

View File

@ -381,6 +381,22 @@
(assert-ok "(and true (or false true))") ; different operators
nil)
(fn test-zero-indexed []
(let [add-opts #{:main.fnl $ :flsproject.fnl "{:lints {:zero-indexed true}}"}]
(check (add-opts "(local x {})
(. x 0)")
[{:code "zero-indexed"
:message "indexing a table with 0; did you forget that Lua is 1-indexed?"}])
(check (add-opts "(. math 0)")
[{:code "zero-indexed"
:message "indexing a table with 0; did you forget that Lua is 1-indexed?"}])
(assert-ok (add-opts "(. math 1)"))
(assert-ok (add-opts "(. arg 0)"))
(assert-ok (add-opts "(. math :0)")))
nil)
{: test-unused
: test-ampersand
: test-unknown-module-field
@ -397,4 +413,5 @@
: test-decreasing-comparison
: test-arg-count
: test-duplicate-keys
: test-nested-associative-operator}
: test-nested-associative-operator
: test-zero-indexed}