Skip to content

Commit

Permalink
Add literals source (with true, false, and nil)
Browse files Browse the repository at this point in the history
Fixes #34.
  • Loading branch information
alexander-yakushev committed Jan 7, 2016
1 parent 81a4847 commit 25aa506
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject compliment "0.2.5"
(defproject compliment "0.2.6-SNAPSHOT"
:description "The Clojure completion library you deserve"
:url "https://github.com/alexander-yakushev/compliment"
:license {:name "Eclipse Public License"
Expand Down
11 changes: 11 additions & 0 deletions src/compliment/sources/special_forms.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,14 @@
:candidates #'candidates
:doc doc
:tag-fn (fn [m _] (assoc m :type :special-form)))

(defn literal-candidates
"We define `true`, `false`, and `nil` in a separate source because they are
not context-dependent (don't have to be first items in the list)."
[prefix _ __]
(filter #(.startsWith ^String % prefix) ["true" "false" "nil"]))

(defsource ::literals
:candidates #'literal-candidates
:doc (constantly nil)
:tag-fn (fn [m _] (assoc m :type :special-form)))
5 changes: 5 additions & 0 deletions test/compliment/sources/t_special_forms.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
(src/candidates "" *ns* (ctx/parse-context '[__prefix__ 42]))
=> nil)

(fact "literals are completed"
(src/literal-candidates "tr" *ns* nil) => ["true"]
(src/literal-candidates "f" *ns* nil) => ["false"]
(src/literal-candidates "n" *ns* nil) => ["nil"])

(fact "there are docs for special forms too"
(src/doc "try" *ns*) => string?
(src/doc "not-a-form" *ns*) => nil))
3 changes: 3 additions & 0 deletions test/compliment/t_core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
(core/completions "recu" {:tag-candidates true}) =>
(contains [{:candidate "recur", :type :special-form}])

(core/completions "tru" {:tag-candidates true}) =>
(contains [{:candidate "true", :type :special-form}])

(core/completions "ba" {:context "(defn foo [bar baz] (+ 1 __prefix__))"
:tag-candidates true}) =>
(contains #{{:candidate "bar", :type :local} {:candidate "baz", :type :local}})
Expand Down

0 comments on commit 25aa506

Please sign in to comment.