Skip to content

Commit

Permalink
Handle slash without anything before it
Browse files Browse the repository at this point in the history
This avoids an NPE on input of "/".
  • Loading branch information
trptcolin committed Jan 3, 2014
1 parent e106888 commit cb31512
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/complete/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@

(defmethod potential-completions :scoped
[prefix ns]
(let [scope (symbol (first (.split prefix "/")))]
(map #(str scope "/" %)
(if-let [class (resolve-class scope)]
(static-members class)
(when-let [ns (or (find-ns scope) (scope (ns-aliases ns)))]
(ns-public-vars ns))))))
(when-let [prefix-scope (first (.split prefix "/"))]
(let [scope (symbol prefix-scope)]
(map #(str scope "/" %)
(if-let [class (resolve-class scope)]
(static-members class)
(when-let [ns (or (find-ns scope) (scope (ns-aliases ns)))]
(ns-public-vars ns)))))))

(defmethod potential-completions :class
[prefix ns]
Expand Down
4 changes: 4 additions & 0 deletions test/complete/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
(is (= '("java.lang.System/out")
(completions "java.lang.System/out")))

(is (= () (completions "fake-ns-here/")))

(is (= () (completions "/")))

(is (some #{"String/valueOf"} (completions "String/")))

(is (not (some #{"String/indexOf" ".indexOf"} (completions "String/")))))

0 comments on commit cb31512

Please sign in to comment.