Skip to content

Commit 0756b2a

Browse files
committed
info and eldoc ops: also return :doc-fragments when available
1 parent 467a799 commit 0756b2a

File tree

7 files changed

+70
-12
lines changed

7 files changed

+70
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
### Changes
66

7+
* `info` and `eldoc` ops: also return `:doc-fragments`, `:doc-first-sentence-fragments`, `:doc-first-sentence-fragments` attributes when available.
8+
* These are explained in https://github.com/clojure-emacs/orchard/blob/v0.15.0/src-newer-jdks/orchard/java/parser_next.clj#L2-L20
9+
* These typically are only available when running a modern JDK through enrich-classpath.
710
* Bump `orchard` to [1.5.0](https://github.com/clojure-emacs/orchard/blob/v0.15.0/CHANGELOG.md#0150-2023-09-20).
811
* Bump `compliment` to [0.4.2](https://github.com/alexander-yakushev/compliment/blob/f7d872d/CHANGELOG.md#042-2023-09-17).
912

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: test quick-test fast-test eastwood cljfmt install fast-install smoketest deploy clean detect_timeout lein-repl repl lint light-kondo
1+
.PHONY: test quick-test fast-test eastwood cljfmt install fast-install smoketest deploy clean detect_timeout lein-repl repl lint light-kondo docs
22
.DEFAULT_GOAL := quick-test
33

44
CLOJURE_VERSION ?= 1.11
@@ -126,3 +126,6 @@ lein-repl: .enrich-classpath-lein-repl
126126
fi
127127

128128
repl: lein-repl
129+
130+
docs:
131+
lein docs

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ PROJECT_VERSION=0.37.1 make fast-install
9292
# Runs clj-kondo, cljfmt and Eastwood (in that order, with fail-fast).
9393
# Please try to run this before pushing commits.
9494
make lint
95+
96+
# Regenerates our user manual.
97+
# When you modify our middleware such that its schema changes, please reflect so in the `cider.nrepl` namespace
98+
# and run:
99+
make docs
95100
```
96101

97102
## Releasing to Clojars

doc/modules/ROOT/pages/nrepl-api/ops.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ Optional parameters::
314314
{blank}
315315

316316
Returns::
317+
* `:doc-block-tags-fragments` May be absent. Represent the 'param', 'returns' and 'throws' sections a Java doc comment. It's a vector of fragments, where fragment is a map with ``:type`` ('text' or 'html') and ``:content`` plain text or html markup, respectively
318+
* `:doc-first-sentence-fragments` May be absent. Represents the first sentence of a Java doc comment. It's a vector of fragments, where fragment is a map with ``:type`` ('text' or 'html') and ``:content`` plain text or html markup, respectively
319+
* `:doc-fragments` May be absent. Represents the body of a Java doc comment, including the first sentence and excluding any block tags. It's a vector of fragments, where fragment is a map with ``:type`` ('text' or 'html') and ``:content`` plain text or html markup, respectively
317320
* `:status` done
318321

319322

@@ -439,6 +442,9 @@ Optional parameters::
439442
{blank}
440443

441444
Returns::
445+
* `:doc-block-tags-fragments` May be absent. Represent the 'param', 'returns' and 'throws' sections a Java doc comment. It's a vector of fragments, where fragment is a map with ``:type`` ('text' or 'html') and ``:content`` plain text or html markup, respectively
446+
* `:doc-first-sentence-fragments` May be absent. Represents the first sentence of a Java doc comment. It's a vector of fragments, where fragment is a map with ``:type`` ('text' or 'html') and ``:content`` plain text or html markup, respectively
447+
* `:doc-fragments` May be absent. Represents the body of a Java doc comment, including the first sentence and excluding any block tags. It's a vector of fragments, where fragment is a map with ``:type`` ('text' or 'html') and ``:content`` plain text or html markup, respectively
442448
* `:status` done
443449

444450

src/cider/nrepl.clj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,27 @@ Depending on the type of the return value of the evaluation this middleware may
205205
:optional wrap-print-optional-arguments
206206
:returns {"formatted-edn" "The formatted data."}}}})
207207

208+
(def fragments-desc
209+
"It's a vector of fragments, where fragment is a map with `:type` ('text' or 'html') and `:content` plain text or html markup, respectively")
210+
211+
(def fragments-doc
212+
{"doc-fragments" (str "May be absent. Represents the body of a Java doc comment, including the first sentence and excluding any block tags. " fragments-desc)
213+
"doc-first-sentence-fragments" (str "May be absent. Represents the first sentence of a Java doc comment. " fragments-desc)
214+
"doc-block-tags-fragments" (str "May be absent. Represent the 'param', 'returns' and 'throws' sections a Java doc comment. " fragments-desc)})
215+
208216
(def-wrapper wrap-info cider.nrepl.middleware.info/handle-info
209217
(cljs/requires-piggieback
210218
{:requires #{#'session}
211219
:handles {"info"
212220
{:doc "Return a map of information about the specified symbol."
213221
:requires {"sym" "The symbol to lookup"
214222
"ns" "The current namespace"}
215-
:returns {"status" "done"}}
223+
:returns (merge {"status" "done"} fragments-doc)}
216224
"eldoc"
217225
{:doc "Return a map of information about the specified symbol."
218226
:requires {"sym" "The symbol to lookup"
219227
"ns" "The current namespace"}
220-
:returns {"status" "done"}}
228+
:returns (merge {"status" "done"} fragments-doc)}
221229
"eldoc-datomic-query"
222230
{:doc "Return a map containing the inputs of the datomic query."
223231
:requires {"sym" "The symbol to lookup"

src/cider/nrepl/middleware/info.clj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@
8181

8282
(defn eldoc-reply
8383
[msg]
84-
(if-let [info (info msg)]
85-
(eldoc/eldoc info)
84+
(if-let [{:keys [doc-first-sentence-fragments doc-fragments doc-block-tags-fragments] :as info} (info msg)]
85+
(cond-> (eldoc/eldoc info)
86+
(seq doc-fragments) (assoc :doc-fragments doc-fragments)
87+
(seq doc-first-sentence-fragments) (assoc :doc-first-sentence-fragments doc-first-sentence-fragments)
88+
(seq doc-block-tags-fragments) (assoc :doc-block-tags-fragments doc-block-tags-fragments))
8689
{:status :no-eldoc}))
8790

8891
(defn eldoc-datomic-query-reply

test/clj/cider/nrepl/middleware/info_test.clj

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
(ns cider.nrepl.middleware.info-test
22
(:require
3-
[clojure.data]
4-
[clojure.test :refer :all]
5-
[clojure.string :as str]
63
[cider.nrepl.middleware.info :as info]
74
[cider.nrepl.test-session :as session]
8-
[cider.test-ns.first-test-ns :as test-ns])
5+
[cider.test-ns.first-test-ns :as test-ns]
6+
[clojure.data]
7+
[clojure.java.io :as io]
8+
[clojure.string :as str]
9+
[clojure.test :refer :all])
910
(:import
10-
[cider.nrepl.test TestClass AnotherTestClass YetAnotherTest]
11-
[org.apache.commons.lang3 SystemUtils]))
11+
(cider.nrepl.test AnotherTestClass TestClass YetAnotherTest)
12+
(org.apache.commons.lang3 SystemUtils)))
1213

1314
(defprotocol FormatResponseTest
1415
(proto-foo [this])
1516
(proto-bar [this] "baz"))
1617

18+
(def enriched-classpath?
19+
"Is enrich-classpath (or something equivalent) augmenting the classpath?"
20+
(boolean (or (io/resource "java/lang/Thread.java")
21+
(io/resource "java.base/java/lang/Thread.java"))))
22+
1723
(deftest format-response-test
1824
(is (re-find #"^(https?|file|jar|zip):" ; resolved either locally or online
1925
(-> (info/info {:class "java.lang.Object" :member "toString"})
@@ -32,7 +38,7 @@
3238
(is (nil? (info/format-response (info/info {:ns "cider.nrepl.middleware.info" :sym "notincanter.core"}))))
3339
;; unfound nses should fall through
3440
(is (nil? (info/format-response (info/info {:ns "cider.nrepl.middleware.nonexistent-namespace" :sym "a-var"}))))
35-
;; protorol docstring
41+
;; protocol docstring
3642
(is (-> (info/format-response (info/info {:ns "cider.nrepl.middleware.info-test" :sym "proto-foo"}))
3743
(contains? "doc")
3844
not))
@@ -106,6 +112,19 @@
106112
(is (= (:doc response) "a macro for testing"))
107113
(is (nil? (:spec response)))))
108114

115+
(when enriched-classpath?
116+
(testing "'fragments' attributes are returned"
117+
(let [{:keys [doc-fragments doc-first-sentence-fragments doc-block-tags-fragments]
118+
:as response}
119+
(session/message {:op "info"
120+
:class "java.lang.Thread"
121+
:member "sleep"})]
122+
(testing (pr-str response)
123+
(doseq [f [doc-fragments doc-first-sentence-fragments doc-block-tags-fragments]]
124+
(is (vector? f))
125+
(is (map? (first f))))
126+
(is (= #{"done"} (:status response)))))))
127+
109128
(testing "get info of a java instance method with return value"
110129
(let [response (session/message {:op "info"
111130
:class "cider.nrepl.test.TestClass"
@@ -317,6 +336,17 @@
317336
(is (not (contains? response :ns)))
318337
(is (= (:type response) "function"))))
319338

339+
(when enriched-classpath?
340+
(testing "Fragments for java interop method with single class"
341+
(let [{:keys [doc-fragments doc-first-sentence-fragments doc-block-tags-fragments]
342+
:as response}
343+
(session/message {:op "eldoc" :member "sleep" :class "java.lang.Thread"})]
344+
(testing (pr-str response)
345+
346+
(doseq [f [doc-fragments doc-first-sentence-fragments doc-block-tags-fragments]]
347+
(is (vector? f))
348+
(is (map? (first f))))))))
349+
320350
(testing "java interop method with single class"
321351
(let [response (session/message {:op "eldoc" :sym ".startsWith" :ns "cider.nrepl.middleware.info-test"})]
322352
(is (= (:class response) ["java.lang.String"])

0 commit comments

Comments
 (0)