File tree Expand file tree Collapse file tree 6 files changed +74
-5
lines changed
test-resources/clojuredocs Expand file tree Collapse file tree 6 files changed +74
-5
lines changed Original file line number Diff line number Diff line change 9
9
* [ #46 ] ( https://github.com/clojure-emacs/orchard/pull/46 ) : [ Inspector] Show fields inherited from superclasses when rendering raw objects.
10
10
* [ #47 ] ( https://github.com/clojure-emacs/orchard/pull/46 ) : [ Java] Cache class-info for editable Java classes.
11
11
* [ #51 ] ( https://github.com/clojure-emacs/orchard/issues/51 ) : Add basic xref functionality in ` orchard.xref ` .
12
+ * [ #64 ] ( https://github.com/clojure-emacs/orchard/issues/64 ) : Add finding docs functionality from ClojureDocs in ` orchard.clojuredocs ` .
12
13
13
14
### Changes
14
15
Original file line number Diff line number Diff line change @@ -11,10 +11,13 @@ TEST_SELECTOR := :java$(JAVA_VERSION)
11
11
12
12
TEST_PROFILES := +test
13
13
14
- test :
14
+ test-resources/clojuredocs/export.edn :
15
+ curl -o $@ https://clojuredocs-edn.netlify.com/export.edn
16
+
17
+ test : test-resources/clojuredocs/export.edn
15
18
lein with-profile +$(VERSION ) ,$(TEST_PROFILES ) test $(TEST_SELECTOR )
16
19
17
- test-watch :
20
+ test-watch : test-resources/clojuredocs/export.edn
18
21
lein with-profile +$(VERSION ) ,$(TEST_PROFILES ) test-refresh $(TEST_SELECTOR )
19
22
20
23
# Eastwood can't handle orchard.java.legacy-parser at the moment, because
Original file line number Diff line number Diff line change
1
+ (ns orchard.clojuredocs
2
+ " Find docs from ClojureDocs and retrieve the result as a map."
3
+ {:author " Masashi Iizuka" }
4
+ (:require
5
+ [clojure.edn :as edn]))
6
+
7
+ (def cache (atom {}))
8
+
9
+ (defn- map-from-key [f coll]
10
+ (reduce #(assoc %1 (f %2 ) %2 ) {} coll))
11
+
12
+ (defn update-documents-cache!
13
+ " Load exported documents file from ClojureDocs, and store it as a cache.
14
+ A EDN format file is expected to the `export-edn-file` argument.
15
+ (e.g. https://clojuredocs-edn.netlify.com/export.edn)"
16
+ {:added " 0.5.0" }
17
+ [export-edn-file]
18
+ (let [docs (-> export-edn-file slurp edn/read-string)]
19
+ (->> (:vars docs)
20
+ (group-by #(:ns %))
21
+ (reduce-kv #(assoc %1 %2 (map-from-key :name %3 )) {})
22
+ (hash-map export-edn-file)
23
+ (reset! cache))
24
+ true ))
25
+
26
+ (defn find-document
27
+ " Find a document matching to ns-name and var-name from cached documents.
28
+ If there are no cached documents corresponding to `export-edn-file`, cache will be updated.
29
+
30
+ Return nil if there is no matching document."
31
+ {:added " 0.5.0" }
32
+ [export-edn-file ns-name var-name]
33
+ (when-not (contains? @cache export-edn-file)
34
+ (update-documents-cache! export-edn-file))
35
+ (get-in @cache [export-edn-file ns-name var-name]))
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ (ns orchard.clojuredocs-test
2
+ (:require
3
+ [clojure.java.io :as io]
4
+ [clojure.test :as test :refer [deftest is testing]]
5
+ [orchard.clojuredocs :as docs]))
6
+
7
+ (def ^:private test-edn-file
8
+ (io/resource " clojuredocs/export.edn" ))
9
+
10
+ (deftest update-documents-cache!-test
11
+ (reset! docs/cache {})
12
+ (is (not (contains? @docs/cache test-edn-file)))
13
+
14
+ (is (true ? (docs/update-documents-cache! test-edn-file)))
15
+ (is (contains? @docs/cache test-edn-file))
16
+ (is (contains? (get @docs/cache test-edn-file) " clojure.core" )))
17
+
18
+ (deftest find-document-test
19
+ (testing " find existing document"
20
+ (let [result (docs/find-document test-edn-file " clojure.core" " first" )]
21
+ (is (map? result))
22
+ (is (every? #(contains? result %)
23
+ [:arglists :doc :examples :name :notes :ns :see-alsos ]))))
24
+
25
+ (testing " find non-existing document"
26
+ (is (nil? (docs/find-document test-edn-file " non-existing-ns" " non-existing-var" )))))
Original file line number Diff line number Diff line change 1
1
(ns orchard.resource-test
2
2
(:require
3
- [clojure.test :refer [deftest testing is]]
3
+ [clojure.string :as str]
4
+ [clojure.test :refer [deftest is testing]]
4
5
[orchard.resource :as resource]))
5
6
6
7
(deftest resource-path-tuple-test
7
8
(is (nil? (resource/resource-path-tuple " jar:file:fake.jar!/fake/file.clj" ))))
8
9
9
10
(deftest project-resources-test
10
11
(testing " get the correct resources for the orchard project"
11
- (is (= " see-also.edn" (-> (resource/project-resources ) first :relpath )))
12
- (is (= java.net.URL (-> (resource/project-resources ) first :url class)))))
12
+ (let [resources (->> (resource/project-resources )
13
+ (remove #(str/ends-with? (.getAbsolutePath (:root %)) " test-resources" )))]
14
+ (is (= " see-also.edn" (-> resources first :relpath )))
15
+ (is (= java.net.URL (-> resources first :url class))))))
You can’t perform that action at this time.
0 commit comments