Skip to content

Commit cd4c118

Browse files
committed
[Fix #3733] Remove support for sideloading
Sideloading was removed in nREPL 1.3, as it was not particularly useful and never gain any meaningful adoption in the broader Clojure community.
1 parent 3c8af8b commit cd4c118

File tree

5 files changed

+1
-207
lines changed

5 files changed

+1
-207
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
- Bump the injected nREPL version to 1.3.
1010
- Bump the injected `cider-nrepl` to [0.49.3](https://github.com/clojure-emacs/cider-nrepl/blob/master/CHANGELOG.md#0493-2024-08-13).
11+
- [#3733](https://github.com/clojure-emacs/cider/issues/3733): Remove support for sideloading. (this experimental feature was removed from nREPL 1.3)
1112

1213
### Bugs fixed
1314

ROADMAP.md

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ There's a bit of info on the subject [here](https://github.com/clojure-emacs/cid
4949

5050
## Implement new nREPL features
5151

52-
* sideloading (there's some experimental support for this)
5352
* dynamic middleware loading
5453
* ~~completion~~
5554
* ~~lookup~~

cider-eval.el

-184
Original file line numberDiff line numberDiff line change
@@ -204,190 +204,6 @@ When invoked with a prefix ARG the command doesn't prompt for confirmation."
204204
(save-excursion
205205
(quit-window nil error-win))))
206206

207-
208-
;;; Sideloader
209-
;;
210-
;; nREPL includes sideloader middleware which provides a Java classloader that
211-
;; is able to dynamically load classes and resources at runtime by interacting
212-
;; with the nREPL client (as opposed to using the classpath of the JVM hosting
213-
;; nREPL server).
214-
;;
215-
;; This performs a similar functionality as the load-file
216-
;; operation, where we can load Clojure namespaces (as source files) or Java
217-
;; classes (as bytecode) by simply requiring or importing them.
218-
;;
219-
;; See https://nrepl.org/nrepl/design/middleware.html#sideloading
220-
221-
(defcustom cider-sideloader-path nil
222-
"List of directories and jar files to scan for sideloader resources.
223-
When not set the cider-nrepl jar will be added automatically when upgrading
224-
an nREPL connection."
225-
:type 'list
226-
:group 'cider
227-
:package-version '(cider . "1.2.0"))
228-
229-
(defcustom cider-dynload-cider-nrepl-version nil
230-
"Version of the cider-nrepl jar used for dynamically upgrading a connection.
231-
Defaults to `cider-required-middleware-version'."
232-
:type 'string
233-
:group 'cider
234-
:package-version '(cider . "1.2.0"))
235-
236-
(defun cider-read-bytes (path)
237-
"Read binary data from PATH.
238-
Return the binary data as unibyte string."
239-
;; based on f-read-bytes
240-
(with-temp-buffer
241-
(set-buffer-multibyte nil)
242-
(setq buffer-file-coding-system 'binary)
243-
(insert-file-contents-literally path nil)
244-
(buffer-substring-no-properties (point-min) (point-max))))
245-
246-
(defun cider-retrieve-resource (dirs name)
247-
"Find a resource NAME in a list DIRS of directories or jar files.
248-
Similar to a classpath lookup. Returns the file contents as a string."
249-
(seq-some
250-
(lambda (path)
251-
(cond
252-
((file-directory-p path)
253-
(let ((expanded (expand-file-name name path)))
254-
(when (file-exists-p expanded)
255-
(cider-read-bytes expanded))))
256-
((and (file-exists-p path) (string-suffix-p ".jar" path))
257-
(cider-jar-retrieve-resource path name))))
258-
dirs))
259-
260-
(defun cider-provide-file (file)
261-
"Provide FILE in a format suitable for sideloading."
262-
(let ((contents (cider-retrieve-resource cider-sideloader-path file)))
263-
(if contents
264-
(base64-encode-string contents 'no-line-breaks)
265-
;; if we can't find the file we should return an empty string
266-
(base64-encode-string ""))))
267-
268-
(defun cider-sideloader-lookup-handler ()
269-
"Make a sideloader-lookup handler."
270-
(lambda (response)
271-
(nrepl-dbind-response response (id status type name)
272-
(if status
273-
(when (member "sideloader-lookup" status)
274-
(cider-request:sideloader-provide id type name))))))
275-
276-
(defun cider-add-middleware-handler (continue)
277-
"Make a add-middleware handler.
278-
CONTINUE is an optional continuation function."
279-
(lambda (response)
280-
(nrepl-dbind-response response (status unresolved-middleware) ;; id middleware
281-
(when unresolved-middleware
282-
(seq-do
283-
(lambda (mw)
284-
(cider-repl-emit-interactive-stderr
285-
(concat "WARNING: middleware " mw " was not found or failed to load.\n")))
286-
unresolved-middleware))
287-
(when (and status (member "done" status) continue)
288-
(funcall continue)))))
289-
290-
(defun cider-request:sideloader-start (&optional connection tooling)
291-
"Perform the nREPL \"sideloader-start\" op.
292-
If CONNECTION is nil, use `cider-current-repl'.
293-
If TOOLING is truthy then the operation is performed over the tooling
294-
session, rather than the regular session."
295-
(cider-ensure-op-supported "sideloader-start")
296-
(cider-nrepl-send-request `("op" "sideloader-start")
297-
(cider-sideloader-lookup-handler)
298-
connection
299-
tooling))
300-
301-
(defun cider-request:sideloader-provide (id type file &optional connection)
302-
"Perform the nREPL \"sideloader-provide\" op for ID, TYPE and FILE.
303-
If CONNECTION is nil, use `cider-current-repl'."
304-
(cider-nrepl-send-request `("id" ,id
305-
"op" "sideloader-provide"
306-
"type" ,type
307-
"name" ,file
308-
"content" ,(cider-provide-file file))
309-
(cider-sideloader-lookup-handler)
310-
connection))
311-
312-
(defun cider-sideloader-start (&optional connection)
313-
"Start nREPL's sideloader.
314-
If CONNECTION is nil, use `cider-current-repl'."
315-
(interactive)
316-
(message "Starting nREPL's sideloader")
317-
(cider-request:sideloader-start connection)
318-
(cider-request:sideloader-start connection 'tooling))
319-
320-
(defvar cider-nrepl-middlewares
321-
'("cider.nrepl/wrap-apropos"
322-
"cider.nrepl/wrap-classpath"
323-
"cider.nrepl/wrap-clojuredocs"
324-
"cider.nrepl/wrap-complete"
325-
"cider.nrepl/wrap-content-type"
326-
"cider.nrepl/wrap-debug"
327-
"cider.nrepl/wrap-enlighten"
328-
"cider.nrepl/wrap-format"
329-
"cider.nrepl/wrap-info"
330-
"cider.nrepl/wrap-inspect"
331-
"cider.nrepl/wrap-log"
332-
"cider.nrepl/wrap-macroexpand"
333-
"cider.nrepl/wrap-ns"
334-
"cider.nrepl/wrap-out"
335-
"cider.nrepl/wrap-slurp"
336-
"cider.nrepl/wrap-profile"
337-
"cider.nrepl/wrap-refresh"
338-
"cider.nrepl/wrap-resource"
339-
"cider.nrepl/wrap-spec"
340-
"cider.nrepl/wrap-stacktrace"
341-
"cider.nrepl/wrap-test"
342-
"cider.nrepl/wrap-trace"
343-
"cider.nrepl/wrap-tracker"
344-
"cider.nrepl/wrap-undef"
345-
"cider.nrepl/wrap-version"
346-
"cider.nrepl/wrap-xref"))
347-
348-
(defun cider-request:add-middleware (middlewares
349-
&optional connection tooling continue)
350-
"Use the nREPL dynamic loader to add MIDDLEWARES to the nREPL session.
351-
352-
- If CONNECTION is nil, use `cider-current-repl'.
353-
- If TOOLING it truthy, use the tooling session instead of the main session.
354-
- CONTINUE is an optional continuation function, which will be called when the
355-
add-middleware op has finished successfully."
356-
(cider-nrepl-send-request `("op" "add-middleware"
357-
"middleware" ,middlewares)
358-
(cider-add-middleware-handler continue)
359-
connection
360-
tooling))
361-
362-
(defun cider-add-cider-nrepl-middlewares (&optional connection)
363-
"Use dynamic loading to add the cider-nrepl middlewares to nREPL.
364-
If CONNECTION is nil, use `cider-current-repl'."
365-
(cider-request:add-middleware
366-
cider-nrepl-middlewares connection nil
367-
(lambda ()
368-
;; When the main session is done adding middleware, then do the tooling
369-
;; session. At this point all the namespaces have been sideloaded so this
370-
;; is faster, we don't want these to race to sideload resources.
371-
(cider-request:add-middleware
372-
cider-nrepl-middlewares connection 'tooling
373-
(lambda ()
374-
;; Ask nREPL again what its capabilities are, so we know which new
375-
;; operations are supported.
376-
(nrepl--init-capabilities (or connection (cider-current-repl))))))))
377-
378-
(defvar cider-required-middleware-version)
379-
(defun cider-upgrade-nrepl-connection (&optional connection)
380-
"Sideload cider-nrepl middleware.
381-
If CONNECTION is nil, use `cider-current-repl'."
382-
(interactive)
383-
(when (not cider-sideloader-path)
384-
(setq cider-sideloader-path (list (cider-jar-find-or-fetch
385-
"cider" "cider-nrepl"
386-
(or cider-dynload-cider-nrepl-version
387-
cider-required-middleware-version)))))
388-
(cider-sideloader-start connection)
389-
(cider-add-cider-nrepl-middlewares connection))
390-
391207

392208
;;; Dealing with compilation (evaluation) errors and warnings
393209
(defun cider-find-property (property &optional backward)

cider-repl.el

-2
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,6 @@ constructs."
16921692
(declare-function cider-version "cider")
16931693
(declare-function cider-test-run-loaded-tests "cider-test")
16941694
(declare-function cider-test-run-project-tests "cider-test")
1695-
(declare-function cider-sideloader-start "cider-eval")
16961695
(cider-repl-add-shortcut "clear-output" #'cider-repl-clear-output)
16971696
(cider-repl-add-shortcut "clear" #'cider-repl-clear-buffer)
16981697
(cider-repl-add-shortcut "clear-banners" #'cider-repl-clear-banners)
@@ -1706,7 +1705,6 @@ constructs."
17061705
(cider-repl-add-shortcut "classpath" #'cider-classpath)
17071706
(cider-repl-add-shortcut "history" #'cider-repl-history)
17081707
(cider-repl-add-shortcut "trace-ns" #'cider-toggle-trace-ns)
1709-
(cider-repl-add-shortcut "sideloader-start" #'cider-sideloader-start)
17101708
(cider-repl-add-shortcut "undef" #'cider-undef)
17111709
(cider-repl-add-shortcut "refresh" #'cider-ns-refresh)
17121710
(cider-repl-add-shortcut "reload" #'cider-ns-reload)

test/cider-eval-tests.el

-20
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,6 @@
3030

3131
;; Please, for each `describe', ensure there's an `it' block, so that its execution is visible in CI.
3232

33-
(describe "cider-provide-file"
34-
(let ((tmp-dir (temporary-file-directory)))
35-
(it "returns an empty string when the file is not found"
36-
(expect (cider-provide-file "abc.clj") :to-equal ""))
37-
(it "base64 encodes without newlines"
38-
(let ((cider-sideloader-path (list tmp-dir))
39-
(default-directory tmp-dir)
40-
(filename (make-temp-file "abc.clj")))
41-
(with-temp-file filename
42-
(dotimes (_ 60) (insert "x")))
43-
(expect (cider-provide-file filename) :not :to-match "\n")))
44-
(it "can handle multibyte characters"
45-
(let ((cider-sideloader-path (list tmp-dir))
46-
(default-directory tmp-dir)
47-
(filename (make-temp-file "abc.clj"))
48-
(coding-system-for-write 'utf-8-unix))
49-
(with-temp-file filename
50-
(insert "🍻"))
51-
(expect (cider-provide-file filename) :to-equal "8J+Nuw==")))))
52-
5333
(describe "cider-extract-error-info"
5434
(it "Matches Clojure compilation exceptions"
5535
(expect (cider-extract-error-info cider-compilation-regexp "Syntax error compiling clojure.core/let at (src/haystack/analyzer.clj:18:1).\n[1] - failed: even-number-of-forms? at: [:bindings] spec: :clojure.core.specs.alpha/bindings\n")

0 commit comments

Comments
 (0)