Skip to content

Commit

Permalink
Merge pull request #178 from ALai57/extend-via-metadata-176
Browse files Browse the repository at this point in the history
Issue 176: Add support for :extend-via-metadata in defprotocol
  • Loading branch information
benjamin-bader authored Jul 12, 2023
2 parents 88fd05a + 2f995e0 commit e8a8524
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/marginalia/parser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,17 @@

(defmethod dispatch-form 'defprotocol
[form raw nspace-sym]
(let [[ds r s] (extract-common-docstring form raw nspace-sym)]
(let [internal-dses (if ds
(extract-internal-docstrings (nthnext form 3))
(extract-internal-docstrings (nthnext form 2)))]
(let [[ds r s] (extract-common-docstring form raw nspace-sym)
;; Clojure 1.10 added `:extend-via-metadata` to the `defprotocol` macro.
;; If the flag is present, `extract-internal-docstrings` needs to start
;; 2 forms later, to account for the presence of a keyword,
;; `:extend-via-metadata` and a boolean `true` in the macro body.
evm (contains? (set form) :extend-via-metadata)]
(let [internal-dses (cond
(and evm ds) (extract-internal-docstrings (nthnext form 5))
evm (extract-internal-docstrings (nthnext form 4))
ds (extract-internal-docstrings (nthnext form 3))
:else (extract-internal-docstrings (nthnext form 2)))]
(with-meta
[ds r s]
{:internal-docstrings internal-dses}))))
Expand Down
2 changes: 2 additions & 0 deletions test/marginalia/test/parse.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
(is (= (count (marginalia.parser/parse "(ns test)\n\"some string\"")) 1))
(is (= (count (marginalia.parser/parse "(ns test (:require [marginalia.parser :as parser]))\n(defn foo [] ::parser/foo)")) 1)))

(deftest extend-via-metadata
(is (marginalia.parser/parse "(ns test)\n(defprotocol Foo \"Does a Foo\" :extend-via-metadata true (do-foo! [_ opts] \"Foo!\"))")))

(def simple-fn
"(defn some-fn
Expand Down

0 comments on commit e8a8524

Please sign in to comment.