Skip to content

Commit

Permalink
Avoid falling back to non-context completions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eerohele committed Feb 20, 2024
1 parent 099933b commit 725f571
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 14 additions & 0 deletions clojure/repl/completions.repl
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
9 changes: 5 additions & 4 deletions clojure/src/tutkain/completions.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
Expand All @@ -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]
Expand Down

0 comments on commit 725f571

Please sign in to comment.