Skip to content

Commit 54340cb

Browse files
committed
Handle multibyte/binary data in sideloader, start tooling sideloader
When serving base64-encoded resources to the sideloader we need to make sure we encode the contents exactly as they are byte for byte, instead of letting Emacs apply character encoding and such. When starting the sideloader also start one on the tooling session.
1 parent d39ff45 commit 54340cb

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [#3020](https://github.com/clojure-emacs/cider/issues/3020): Fix session linking on Windows, e.g. when jumping into a library on the classpath.
1313
* [#3031](https://github.com/clojure-emacs/cider/pull/3031): Fix `cider-eval-defun-up-to-point` failing to match delimiters correctly in some cases, resulting in reader exceptions.
1414
* [#3039](https://github.com/clojure-emacs/cider/pull/3039): Allow starting the sideloader for the tooling session
15+
* [#3031](https://github.com/clojure-emacs/cider/pull/3041): Handle binary/multibyte data when serving sideloaded resources
1516

1617
## 1.1.1 (2021-05-24)
1718

cider-eval.el

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,29 @@ When invoked with a prefix ARG the command doesn't prompt for confirmation."
189189

190190
;;; Sideloader
191191

192-
(defvar cider-sideloader-dir (file-name-directory load-file-name))
192+
(defvar cider-sideloader-dirs
193+
(list (file-name-directory load-file-name))
194+
"Directories where we look for resources requested by the sideloader")
195+
196+
;; based on f-read-bytes
197+
(defun cider-read-bytes (path)
198+
"Read binary data from PATH.
199+
Return the binary data as unibyte string."
200+
(with-temp-buffer
201+
(set-buffer-multibyte nil)
202+
(setq buffer-file-coding-system 'binary)
203+
(insert-file-contents-literally path nil)
204+
(buffer-substring-no-properties (point-min) (point-max))))
193205

194206
(defun cider-provide-file (file)
195207
"Provide FILE in a format suitable for sideloading."
196-
(let ((file (expand-file-name file cider-sideloader-dir)))
197-
(if (file-exists-p file)
198-
(with-current-buffer (find-file-noselect file)
199-
(base64-encode-string (substring-no-properties (buffer-string)) 'no-line-breaks))
208+
(let ((file (seq-find
209+
#'file-exists-p
210+
(seq-map (lambda (dir)
211+
(expand-file-name file dir))
212+
cider-sideloader-dirs))))
213+
(if file
214+
(base64-encode-string (cider-read-bytes file) 'no-line-breaks)
200215
;; if we can't find the file we should return an empty string
201216
(base64-encode-string ""))))
202217

@@ -235,7 +250,8 @@ If CONNECTION is nil, use `cider-current-repl'."
235250
If CONNECTION is nil, use `cider-current-repl'."
236251
(interactive)
237252
(message "Starting nREPL's sideloader")
238-
(cider-request:sideloader-start connection))
253+
(cider-request:sideloader-start connection)
254+
(cider-request:sideloader-start connection 'tooling))
239255

240256

241257
;;; Dealing with compilation (evaluation) errors and warnings

0 commit comments

Comments
 (0)