Skip to content

Commit 0b44054

Browse files
[info] Add support for sources JAR downloading on `info' events
1 parent 356c2bd commit 0b44054

File tree

2 files changed

+52
-17
lines changed

2 files changed

+52
-17
lines changed

cider-client.el

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,20 @@ the current connection. Return the id of the sent message.
189189
If TOOLING is truthy then the tooling session is used."
190190
(nrepl-send-request request callback (or connection (cider-current-repl 'any 'ensure)) tooling))
191191

192-
(defun cider-nrepl-send-sync-request (request &optional connection abort-on-input)
192+
(defun cider-nrepl-send-sync-request (request &optional connection
193+
abort-on-input callback)
193194
"Send REQUEST to the nREPL server synchronously using CONNECTION.
194195
Hold till final \"done\" message has arrived and join all response messages
195196
of the same \"op\" that came along and return the accumulated response.
196197
If ABORT-ON-INPUT is non-nil, the function will return nil
197198
at the first sign of user input, so as not to hang the
198-
interface."
199+
interface.
200+
if CALLBACK is non-nil, it will additionally be called on all received messages."
199201
(nrepl-send-sync-request request
200202
(or connection (cider-current-repl 'any 'ensure))
201-
abort-on-input))
203+
abort-on-input
204+
nil
205+
callback))
202206

203207
(defun cider-nrepl-send-unhandled-request (request &optional connection)
204208
"Send REQUEST to the nREPL CONNECTION and ignore any responses.
@@ -342,6 +346,15 @@ The default value in nREPL is 1024."
342346
:group 'cider
343347
:package-version '(cider . "0.25.0"))
344348

349+
(defcustom cider-download-sources-jars nil
350+
"When enabled, CIDER will attempt to download sources artifact for 3rd-party
351+
dependencies from Maven if they are not found locally. This downloading
352+
will only happen once per artifact, and only during \"Jump to definiton\"
353+
and `cider-doc' user actions."
354+
:type 'boolean
355+
:group 'cider
356+
:package-version '(cider . "1.17.0"))
357+
345358
(defun cider--print-fn ()
346359
"Return the value to send in the nrepl.middleware.print/print slot."
347360
(pcase cider-print-fn
@@ -681,13 +694,31 @@ CONTEXT represents a completion context for compliment."
681694

682695
(defun cider-sync-request:info (symbol &optional class member context)
683696
"Send \"info\" op with parameters SYMBOL or CLASS and MEMBER, honor CONTEXT."
684-
(let ((var-info (thread-first `("op" "info"
685-
"ns" ,(cider-current-ns)
686-
,@(when symbol `("sym" ,symbol))
687-
,@(when class `("class" ,class))
688-
,@(when member `("member" ,member))
689-
,@(when context `("context" ,context)))
690-
(cider-nrepl-send-sync-request (cider-current-repl)))))
697+
(let* ((report-jar-downloading
698+
(lambda (coords)
699+
(message "Local source not found, downloading Java sources for artifact %s/%s %s..."
700+
(nrepl-dict-get coords "group")
701+
(nrepl-dict-get coords "artifact")
702+
(nrepl-dict-get coords "version"))))
703+
(var-info (thread-first
704+
`("op" "info"
705+
"ns" ,(cider-current-ns)
706+
,@(when symbol `("sym" ,symbol))
707+
,@(when class `("class" ,class))
708+
,@(when member `("member" ,member))
709+
,@(when context `("context" ,context))
710+
,@(when cider-download-sources-jars
711+
`("download-sources-jar" "1"
712+
;; TODO
713+
"build-tool" "clojure")))
714+
(cider-nrepl-send-sync-request
715+
(cider-current-repl)
716+
nil
717+
(lambda (resp)
718+
(let* ((status (nrepl-dict-get resp "status")))
719+
(when (member "download-sources-jar" status)
720+
(funcall report-jar-downloading
721+
(nrepl-dict-get resp "coords")))))))))
691722
(if (member "no-info" (nrepl-dict-get var-info "status"))
692723
nil
693724
var-info)))

nrepl-client.el

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -939,21 +939,25 @@ the standard session."
939939
(declare-function cider-repl-emit-interactive-stderr "cider-repl")
940940
(declare-function cider--render-stacktrace-causes "cider-eval")
941941

942-
(defun nrepl-send-sync-request (request connection &optional abort-on-input tooling)
942+
(defun nrepl-send-sync-request (request connection &optional abort-on-input
943+
tooling callback)
943944
"Send REQUEST to the nREPL server synchronously using CONNECTION.
944945
Hold till final \"done\" message has arrived and join all response messages
945946
of the same \"op\" that came along.
946947
If ABORT-ON-INPUT is non-nil, the function will return nil at the first
947948
sign of user input, so as not to hang the interface.
948-
If TOOLING, use the tooling session rather than the standard session."
949+
If TOOLING, use the tooling session rather than the standard session.
950+
If CALLBACK is non-nil, it will additionally be called on all received messages."
949951
(let* ((time0 (current-time))
950952
(response (cons 'dict nil))
951953
(nrepl-ongoing-sync-request t)
954+
(cb (lambda (resp)
955+
;; If caller has provided `callback', call it on the response.
956+
(when callback
957+
(funcall callback resp))
958+
(nrepl--merge response resp)))
952959
status)
953-
(nrepl-send-request request
954-
(lambda (resp) (nrepl--merge response resp))
955-
connection
956-
tooling)
960+
(nrepl-send-request request cb connection tooling)
957961
(while (and (not (member "done" status))
958962
(not (and abort-on-input
959963
(input-pending-p))))
@@ -962,7 +966,7 @@ If TOOLING, use the tooling session rather than the standard session."
962966
;; anywhere, and we'll just timeout. So we forward it to the user.
963967
(if (member "need-input" status)
964968
(progn (cider-need-input (current-buffer))
965-
;; If the used took a few seconds to respond, we might
969+
;; If the user took a few seconds to respond, we might
966970
;; unnecessarily timeout, so let's reset the timer.
967971
(setq time0 (current-time)))
968972
;; break out in case we don't receive a response for a while

0 commit comments

Comments
 (0)