Skip to content

Commit

Permalink
trust cljs analyzer to read macros correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
martinklepsch committed Nov 9, 2018
1 parent b205a2e commit 3079986
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
23 changes: 2 additions & 21 deletions codox/src/codox/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(:require [clojure.string :as str]
[clojure.java.shell :as shell]
[codox.reader.clojure :as clj]
[codox.reader.clojurescript :as cljs]
[codox.reader.plaintext :as text]))

(defn- writer [{:keys [writer]}]
Expand All @@ -19,29 +20,9 @@
(throw
(Exception. (str "Could not resolve codox writer " writer-sym))))))

(defn- macro? [var]
(= (:type var) :macro))

(defn- read-macro-namespaces [paths read-opts]
(->> (clj/read-namespaces paths read-opts)
(map (fn [ns] (update-in ns [:publics] #(filter macro? %))))
(remove (comp empty? :publics))))

(defn- merge-namespaces [namespaces]
(for [[name namespaces] (group-by :name namespaces)]
(assoc (first namespaces) :publics (mapcat :publics namespaces))))

(defn- cljs-read-namespaces [paths read-opts]
;; require is here to allow Clojure 1.3 and 1.4 when not using ClojureScript
(require 'codox.reader.clojurescript)
(let [reader (find-var 'codox.reader.clojurescript/read-namespaces)]
(merge-namespaces
(concat (reader paths read-opts)
(read-macro-namespaces paths read-opts)))))

(def ^:private namespace-readers
{:clojure clj/read-namespaces
:clojurescript cljs-read-namespaces})
:clojurescript cljs/read-namespaces})

(defn- var-symbol [namespace var]
(symbol (name (:name namespace)) (name (:name var))))
Expand Down
19 changes: 10 additions & 9 deletions codox/src/codox/reader/clojurescript.clj
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@
:else :var))

(defn- read-var [file vars var]
(-> var
(select-keys [:name :line :arglists :doc :dynamic :added :deprecated :doc/format])
(update-some :name (comp symbol name))
(update-some :arglists remove-quote)
(update-some :doc correct-indent)
(assoc-some :file (.getPath file)
:type (var-type var)
:members (map (partial read-var file vars)
(protocol-methods var vars)))))
(let [vt (var-type var)]
(-> var
(select-keys [:name :line :arglists :doc :dynamic :added :deprecated :doc/format])
(update-some :name (comp symbol name))
(update-some :arglists remove-quote)
(update-some :doc correct-indent)
(assoc-some :file (if (= vt :macro) (:file var) (.getPath file))
:type vt
:members (map (partial read-var file vars)
(protocol-methods var vars))))))

(defn- read-publics [state namespace file]
(let [vars (vals (ana/ns-publics state namespace))]
Expand Down

0 comments on commit 3079986

Please sign in to comment.