From 725f571681eeca9eaf870ea74ad6dc6990a10dbb Mon Sep 17 00:00:00 2001 From: Eero Helenius Date: Tue, 20 Feb 2024 12:17:52 +0200 Subject: [PATCH] Avoid falling back to non-context completions If there are no context completions (e.g. if there are no namespaces starting with the prefix), prior to this commit, Tutkain would suggest non-context completions instead. --- clojure/repl/completions.repl | 14 ++++++++++++++ clojure/src/tutkain/completions.cljc | 9 +++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/clojure/repl/completions.repl b/clojure/repl/completions.repl index f6a0187a..33b9189d 100644 --- a/clojure/repl/completions.repl +++ b/clojure/repl/completions.repl @@ -437,3 +437,17 @@ (spec/and (prefixed-candidates ::specs/class-completions "j") (partial not-any? (comp #{:snippet} :completion-type)))) + +(intern (the-ns 'user) 'NONE) + +;; do not propose non-context completions if there are no context completions +(completions + {:prefix "NONE" + :ns "user" + :enclosing-sexp "(require '[])" + :start-line 1 + :start-column 1 + :line 1 + :column 12}) + +(xr/check! empty?) diff --git a/clojure/src/tutkain/completions.cljc b/clojure/src/tutkain/completions.cljc index e3ea2e99..d5ac5691 100644 --- a/clojure/src/tutkain/completions.cljc +++ b/clojure/src/tutkain/completions.cljc @@ -631,7 +631,7 @@ (require-completions loc prefix)) clojure.core/import (let [loc (find-loc form line column)] (import-completions loc prefix)) - []))) + ::none))) (defn ^:private find-completions [{:keys [file ns prefix enclosing-sexp start-line start-column line column] :as message}] @@ -643,9 +643,10 @@ {:features #{:clj :t.a.jvm} :read-cond :allow} start-line start-column)))] - (or - (not-empty (context-completions (peek forms) prefix line column)) - (into (local-completions forms message) (candidates prefix ns))))) + (let [context-completions (context-completions (peek forms) prefix line column)] + (if (not (identical? ::none context-completions)) + context-completions + (into (local-completions forms message) (candidates prefix ns)))))) (defmethod completions :default [message]