Skip to content

Commit f65ec8a

Browse files
committed
Implement hot reloading for java
- fixes #33
1 parent 43c6727 commit f65ec8a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

dap-java.el

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ If the port is taken, DAP will try the next port."
6363
(const always)
6464
(const never)))
6565

66+
(defcustom dap-java-hot-reload 'always
67+
"How to perfor hot reload."
68+
:group 'dap-java
69+
:type '(choice (const always)
70+
(const never)))
71+
6672
(defcustom dap-java-test-additional-args ()
6773
"Additional arguments for JUnit standalone runner."
6874
:group 'dap-java
@@ -285,6 +291,14 @@ attaching to the test."
285291
port)
286292
nil))))
287293

294+
(cl-defmethod dap-handle-event ((event (eql hotcodereplace)) session _params)
295+
(when (eq dap-java-hot-reload 'always)
296+
(setq my/session session)
297+
(-let [(&hash "changedClasses" classes) (dap-request session "redefineClasses")]
298+
(if classes
299+
(lsp--info "Reloaded the following classes: %s." classes)
300+
(lsp--warn "There are no classes to redefine.")))))
301+
288302
(dap-register-debug-provider "java" #'dap-java--populate-default-args)
289303
(dap-register-debug-template "Java Run Configuration"
290304
(list :type "java"

dap-mode.el

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,15 @@ thread exection but the server will log message."
758758
(dap--insert-at-point-max str))
759759
(setq-local buffer-read-only t)))
760760

761+
(cl-defgeneric dap-handle-event (event-type session params)
762+
"Extension point for handling custom events.
763+
EVENT-TYPE is the event to handle.
764+
SESSION is the session that has triggered the event.
765+
PARAMS are the event params.")
766+
767+
(cl-defmethod dap-handle-event (event-type _session _params)
768+
(message "No message handler for %s" event-type))
769+
761770
(defun dap--on-event (debug-session event)
762771
"Dispatch EVENT for DEBUG-SESSION."
763772
(-let [(&hash "body" "event" event-type) event]
@@ -832,7 +841,8 @@ thread exection but the server will log message."
832841
(-let [(&hash "body" (&hash "source")) event]
833842
(cl-pushnew source (dap--debug-session-loaded-sources debug-session))
834843
(run-hook-with-args 'dap-loaded-sources-changed-hook debug-session)))
835-
(_ (message "No message handler for %s" event-type)))))
844+
(_ (dap-handle-event (intern event-type) debug-session body)))))
845+
836846

837847
(defun dap--create-filter-function (debug-session)
838848
"Create filter function for DEBUG-SESSION."

0 commit comments

Comments
 (0)