@@ -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 )
0 commit comments