Skip to content

Commit

Permalink
Support :require/:import without brackets/parens
Browse files Browse the repository at this point in the history
  • Loading branch information
eerohele committed Feb 20, 2024
1 parent 725f571 commit 99894af
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
32 changes: 32 additions & 0 deletions clojure/repl/completions.repl
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,35 @@
:column 12})

(xr/check! empty?)

;; :require without brackets

(completions
{:prefix "c"
:ns "user"
:enclosing-sexp "(ns foo.bar (:require ))"
:start-line 1
:start-column 1
:line 1
:column 23})

(xr/check!
(spec/and
(prefixed-candidates ::specs/ns-completions "c")
(partial not-any? (comp #{:snippet} :completion-type))))

;; import without parens

(completions
{:prefix "j"
:ns "user"
:enclosing-sexp "(ns foo.bar (:import ))"
:start-line 1
:start-column 1
:line 1
:column 22})

(xr/check!
(spec/and
(prefixed-candidates ::specs/class-completions "j")
(partial not-any? (comp #{:snippet} :completion-type))))
6 changes: 5 additions & 1 deletion clojure/src/tutkain/completions.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,16 @@
(defn ns-form-completions
[form prefix line column]
(let [loc (find-loc form line column)
node (some-> loc zip/node)
head (some-> loc zip/leftmost zip/node)]
(case head
:require (require-completions loc prefix)
:import (import-completions loc prefix)
:refer-clojure (ns-public-var-candidates 'clojure.core)
ns-form-snippets)))
(case (first node)
:require (candidates-for-prefix prefix (ns-candidates))
:import (class-candidates prefix)
ns-form-snippets))))

(defn context-completions
[form prefix line column]
Expand Down

0 comments on commit 99894af

Please sign in to comment.