diff --git a/src/fennel-ls/completion.fnl b/src/fennel-ls/completion.fnl index e5fb271..60486eb 100644 --- a/src/fennel-ls/completion.fnl +++ b/src/fennel-ls/completion.fnl @@ -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) diff --git a/test/completion.fnl b/test/completion.fnl index b81e6fc..680b950 100644 --- a/test/completion.fnl +++ b/test/completion.fnl @@ -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 diff --git a/test/lint.fnl b/test/lint.fnl index e7a822d..a4ce73f 100644 --- a/test/lint.fnl +++ b/test/lint.fnl @@ -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}