Skip to content

Commit 85b984f

Browse files
Merge pull request #9 from clj-codes/feat/adds-extra-definitions-config
feat: adds extra definitions in config / manual lists
2 parents 0cecfb8 + b16998d commit 85b984f

File tree

5 files changed

+101
-14
lines changed

5 files changed

+101
-14
lines changed

dev/playground.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,21 @@
6565
db (d/db conn)
6666
result (doall (->> (d/q '[:find [(pull ?e [:definition/id
6767
:definition/name
68+
:definition/doc
6869
:definition/group
6970
:definition/artifact
7071
:definition/git-source
7172
{:definition/namespace [:namespace/name]}]) ...]
7273
:in $ ?q
7374
:where
74-
[(str ".*" ?q ".*") ?pattern]
75+
[(str ?q ".*") ?pattern]
7576
[(re-pattern ?pattern) ?regex]
7677
[(re-matches ?regex ?name)]
7778
[?e :definition/name ?name]
7879
[?e :definition/private false]
7980
(not [?e :definition/defined-by "cljs.core/defprotocol"])]
8081
db
81-
"assoc")
82+
"def")
8283
(sort-by (juxt
8384
:definition/id
8485
:definition/name))))]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[{:name "def",
2+
:ns "clojure.core",
3+
:doc
4+
"Creates and interns or locates a global var with the name of symbol and a\nnamespace of the value of the current namespace (*ns*). See\nhttp://clojure.org/special_forms for more information.",
5+
:meta {:type "special-form"}}
6+
{:name "if",
7+
:ns "clojure.core",
8+
:doc "Evaluates test.",
9+
:meta {:type "special-form"}}
10+
{:name "do",
11+
:ns "clojure.core",
12+
:doc
13+
"Evaluates the expressions in order and returns the value of the last. If no\nexpressions are supplied, returns nil. See http://clojure.org/special_forms\nfor more information.",
14+
:meta {:type "special-form"}}
15+
{:name "quote",
16+
:ns "clojure.core",
17+
:doc
18+
"Yields the unevaluated form. See http://clojure.org/special_forms for more\ninformation.",
19+
:meta {:type "special-form"}}
20+
{:name "var",
21+
:ns "clojure.core",
22+
:doc
23+
"The symbol must resolve to a var, and the Var object itself (not its value)\nis returned. The reader macro #'x expands to (var x). See\nhttp://clojure.org/special_forms for more information.",
24+
:meta {:type "special-form"}}
25+
{:name "recur",
26+
:ns "clojure.core",
27+
:doc
28+
"Evaluates the exprs in order, then, in parallel, rebinds the bindings of\nthe recursion point to the values of the exprs. See\nhttp://clojure.org/special_forms for more information.",
29+
:meta {:type "special-form"}}
30+
{:name "throw",
31+
:ns "clojure.core",
32+
:doc
33+
"The expr is evaluated and thrown, therefore it should yield an instance of\nsome derivee of Throwable. Please see http://clojure.org/special_forms#throw",
34+
:meta {:type "special-form"}}
35+
{:name "try",
36+
:ns "clojure.core",
37+
:doc
38+
"The exprs are evaluated and, if no exceptions occur, the value of the last\nis returned. If an exception occurs and catch clauses are provided, each is\nexamined in turn and the first for which the thrown exception is an instance\nof the named class is considered a matching catch clause. If there is a\nmatching catch clause, its exprs are evaluated in a context in which name is\nbound to the thrown exception, and the value of the last is the return value\nof the function. If there is no matching catch clause, the exception\npropagates out of the function. Before returning, normally or abnormally,\nany finally exprs will be evaluated for their side effects. See\nhttp://clojure.org/special_forms for more information.",
39+
:meta {:type "special-form"}}
40+
{:name "catch",
41+
:ns "clojure.core",
42+
:doc
43+
"The exprs are evaluated and, if no exceptions occur, the value of the last\nis returned. If an exception occurs and catch clauses are provided, each is\nexamined in turn and the first for which the thrown exception is an instance\nof the named class is considered a matching catch clause. If there is a\nmatching catch clause, its exprs are evaluated in a context in which name is\nbound to the thrown exception, and the value of the last is the return value\nof the function. If there is no matching catch clause, the exception\npropagates out of the function. Before returning, normally or abnormally,\nany finally exprs will be evaluated for their side effects. See\nhttp://clojure.org/special_forms for more information.",
44+
:meta {:type "special-form"}}
45+
{:name "finally",
46+
:ns "clojure.core",
47+
:doc
48+
"The exprs are evaluated and, if no exceptions occur, the value of the last\nis returned. If an exception occurs and catch clauses are provided, each is\nexamined in turn and the first for which the thrown exception is an instance\nof the named class is considered a matching catch clause. If there is a\nmatching catch clause, its exprs are evaluated in a context in which name is\nbound to the thrown exception, and the value of the last is the return value\nof the function. If there is no matching catch clause, the exception\npropagates out of the function. Before returning, normally or abnormally,\nany finally exprs will be evaluated for their side effects. See\nhttp://clojure.org/special_forms for more information.",
49+
:meta {:type "special-form"}}
50+
{:name ".",
51+
:ns "clojure.core",
52+
:doc
53+
"The '.' special form is the basis for access to Java. It can be considered\na member-access operator, and/or read as 'in the scope of'. See\nhttp://clojure.org/special_forms for more information.",
54+
:meta {:type "special-form"}}
55+
{:name "set!",
56+
:ns "clojure.core",
57+
:doc
58+
"Assignment special form. When the first operand is a field member access\nform, the assignment is to the corresponding field. If it is an instance\nfield, the instance expr will be evaluated, then the expr. In all cases\nthe value of expr is returned. Note - you cannot assign to function params\nor local bindings. Only Java fields, Vars, Refs and Agents are mutable in\nClojure. See http://clojure.org/special_forms for more information.",
59+
:meta {:type "special-form"}}
60+
{:name "monitor-enter",
61+
:ns "clojure.core",
62+
:doc
63+
"A synchronization primitive that should be avoided in user code. Use the\nlocking macro. See http://clojure.org/special_forms for more information.",
64+
:meta {:type "special-form"}}
65+
{:name "monitor-exit",
66+
:ns "clojure.core",
67+
:doc
68+
"A synchronization primitive that should be avoided in user code. Use the\nlocking macro. See http://clojure.org/special_forms for more information.",
69+
:meta {:type "special-form"}}
70+
{:name "new",
71+
:ns "clojure.core",
72+
:doc
73+
"Instantiate a class. See http://clojure.org/java_interop#new for\nmore information.",
74+
:meta {:type "special-form"}}]

resources/config.edn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
:deps {org.clojure/clojure
33
{:git/url "https://github.com/clojure/clojure"
44
:git/tag "clojure-1.11.1"
5-
:git/sha "ce55092f2b2f5481d25cff6205470c1335760ef6"}
5+
:git/sha "ce55092f2b2f5481d25cff6205470c1335760ef6"
6+
:extras {:definitions ["clojure.core/special-forms.edn"]}}
67
org.clojure/core.logic
78
{:git/url "https://github.com/clojure/core.logic"
89
:git/tag "v1.0.1"

src/codes/clj/docs/extractor/adapters.clj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,15 @@
121121
defined-by filename macro col name-col end-col
122122
arglist-strs varargs-min-arity doc row
123123
private protocol-ns protocol-name]}]
124-
(let [trim-filename (str/replace filename root "")]
124+
(let [trim-filename (when filename (str/replace filename root ""))]
125125
(assoc-some
126126
{:definition/group group
127127
:definition/artifact artifact
128128
:definition/name (str name)}
129129
:definition/defined-by (some-> defined-by str)
130-
:definition/namespace (when ns {:namespace/id (str/join "/" [group artifact ns])
131-
:namespace/name (str ns)})
130+
:definition/namespace (when ns
131+
{:namespace/id (str/join "/" [group artifact ns])
132+
:namespace/name (str ns)})
132133
:definition/fixed-arities fixed-arities
133134
:definition/arglist-strs arglist-strs
134135
:definition/end-row end-row
@@ -139,13 +140,14 @@
139140
:definition/added added
140141
:definition/author author
141142
:definition/filename trim-filename
142-
:definition/git-source (str url "/blob/" tag trim-filename "#L" row)
143+
:definition/git-source (when trim-filename
144+
(str url "/blob/" tag trim-filename "#L" row))
143145
:definition/col col
144146
:definition/name-col name-col
145147
:definition/end-col end-col
146148
:definition/doc doc
147149
:definition/row row
148-
:definition/macro (boolean macro)
150+
:definition/macro (some-> macro boolean)
149151
:definition/varargs-min-arity varargs-min-arity
150152
:definition/private (boolean private)
151153
:definition/protocol-ns (some-> protocol-ns str)

src/codes/clj/docs/extractor/analysis.clj

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
(ns codes.clj.docs.extractor.analysis
22
(:require [clj-kondo.core :as kondo]
3+
[clojure.edn :as edn]
4+
[clojure.java.io :as io]
35
[clojure.tools.deps :as deps]))
46

57
(defn download-project!
@@ -24,17 +26,24 @@
2426
(dissoc :namespace-usages
2527
:var-usages)))
2628

29+
(defn extract-extras!
30+
[paths]
31+
(reduce (fn [accum path] (into accum (-> path io/resource slurp edn/read-string)))
32+
[]
33+
paths))
34+
2735
(defn extract-analysis!
28-
[project git]
29-
(let [{:keys [paths] :as project-meta} (download-project! project git)
30-
{:keys [var-definitions namespace-definitions]} (kondo-run! paths)]
36+
[project-name project-config]
37+
(let [{:keys [paths] :as project-meta} (download-project! project-name project-config)
38+
{:keys [var-definitions namespace-definitions]} (kondo-run! paths)
39+
extra-definitions (extract-extras! (-> project-config :extras :definitions))]
3140
{:project project-meta
3241
:namespaces namespace-definitions
33-
:definitions var-definitions}))
42+
:definitions (into var-definitions extra-definitions)}))
3443

3544
(defn extract!
3645
[config]
3746
(->> config
3847
:deps
39-
(mapv (fn [[project git]]
40-
(extract-analysis! project git)))))
48+
(mapv (fn [[project-name project-config]]
49+
(extract-analysis! project-name project-config)))))

0 commit comments

Comments
 (0)