commit 9caa3deb42d3a859c6a386848b63391cbad713dd (HEAD -> refs/heads/main)
Author: Phil Hagelberg <phil@hagelb.org>
Date:   Thu Jun 3 21:05:15 2021 -0700

    In repl completion, respect shadowing.
    
    If there's a match in macros, it should not look at locals or globals.

    Modified   src/fennel/repl.fnl
diff --git a/src/fennel/repl.fnl b/src/fennel/repl.fnl
index 7ea52ad..9e153ad 100644
--- a/src/fennel/repl.fnl
+++ b/src/fennel/repl.fnl
@@ -142,6 +142,8 @@ For more information about the language, see https://fennel-lang.org/reference")
 (fn completer [env scope text]
   (let [matches []
         input-fragment (text:gsub ".*[%s)(]+" "")]
+    (var stop-looking? false)
+
     (fn add-partials [input tbl prefix] ; add partial key matches in tbl
       (each [k (utils.allpairs tbl)]
         (let [k (if (or (= tbl env) (= tbl env.___replLocals___))
@@ -161,13 +163,14 @@ For more information about the language, see https://fennel-lang.org/reference")
                                (. scope.manglings head)
                                head)]
               (when (= (type (. tbl raw-head)) :table)
+                (set stop-looking? true)
                 (add-matches tail (. tbl raw-head) (.. prefix head)))))))
 
-    (add-matches input-fragment (or scope.specials []))
-    (add-matches input-fragment (or scope.macros []))
-    (add-matches input-fragment (or env.___replLocals___ []))
-    (add-matches input-fragment env)
-    (add-matches input-fragment (or env._ENV env._G []))
+    (each [_ source (ipairs [scope.specials scope.macros
+                             (or env.___replLocals___ []) env])]
+      (add-matches input-fragment source)
+      ;; bootstrap compiler doesn't yet know how to :until
+      (when stop-looking? (lua :break)))
     matches))
 
 (fn repl [options]
    Modified   test/repl.fnl
diff --git a/test/repl.fnl b/test/repl.fnl
index 10db57b..3dad29f 100644
--- a/test/repl.fnl
+++ b/test/repl.fnl
@@ -37,7 +37,15 @@
     (assert-equal-unordered (send "(values !x-y !x_y)") [[1 2]]
                             "mangled locals do not collide")
     (assert-equal-unordered (comp "!x") ["!x_y" "!x-y"]
-                            "completions on mangled locals do not collide")))
+                            "completions on mangled locals do not collide"))
+  (let [(send comp) (wrap-repl)]
+    (send "(local mac {:incremented 9 :unsanitary 2})")
+    (send "(import-macros mac :test.macros)")
+    (let [[c1 c2 c3] (doto (comp "mac.i") table.sort)]
+      ;; local should be shadowed!
+      (l.assertNotEquals c1 "mac.incremented")
+      (l.assertNotEquals c2 "mac.incremented")
+      (l.assertNil c3))))
 
 (fn test-help []
   (let [send (wrap-repl)

[back] 

Generated by Phil Hagelberg using scpaste at Thu Jun 3 21:05:23 2021. PDT. (original)