Skip to content

Commit adadab0

Browse files
committed
Add module request support
1 parent a1c3bf9 commit adadab0

File tree

3 files changed

+63
-9
lines changed

3 files changed

+63
-9
lines changed

src/cl-jupyter/kernel.lisp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,9 @@
201201
(multiple-value-call #'values pathname (source-line-column pathname (ccl:source-note-start-pos source-note)))))
202202
#+clasp (let ((pos (clasp-debug:frame-source-position frame)))
203203
(when pos
204-
(let ((pathname (clasp-debug:code-source-line-pathname pos)))
205-
(values (if (and (uiop:physical-pathname-p pathname)
206-
(not (uiop:absolute-pathname-p pathname)))
207-
(merge-pathnames (make-pathname :host "CELL" :version :newest)
208-
pathname)
209-
pathname)
210-
(clasp-debug:code-source-line-line-number pos)
211-
(clasp-debug:code-source-line-column pos)))))
204+
(values (clasp-debug:code-source-line-pathname pos)
205+
(clasp-debug:code-source-line-line-number pos)
206+
(clasp-debug:code-source-line-column pos))))
212207
#+cmucl (let* ((code-location (di:frame-code-location frame))
213208
(debug-source (di:code-location-debug-source code-location))
214209
(pathname (ignore-errors (di:debug-source-name debug-source))))
@@ -261,13 +256,36 @@
261256
instance)
262257
frames))
263258

259+
(defvar *modules* nil)
260+
(defvar *system-name* "")
261+
262+
(defgeneric grovel-component (component)
263+
(:method (component)
264+
(declare (ignore component)))
265+
(:method :around ((component asdf:component))
266+
(when (or (not (asdf::component-if-feature component))
267+
(uiop:featurep (asdf::component-if-feature component)))
268+
(call-next-method)))
269+
(:method ((component asdf:cl-source-file))
270+
(push (make-instance 'jupyter:debug-module
271+
:name (format nil "~a ~a" *system-name* (asdf:component-name component))
272+
:path (asdf:component-pathname component))
273+
*modules*))
274+
(:method ((component asdf:parent-component))
275+
(loop for child in (asdf:component-children component)
276+
do (grovel-component child))))
277+
278+
(defmethod jupyter:debug-modules ((kernel kernel))
279+
(loop with *modules* = nil
280+
for *system-name* in (asdf:already-loaded-systems)
281+
finally (return *modules*)
282+
do (grovel-component (asdf:find-system *system-name*))))
264283

265284
(defmethod jupyter:debug-object-children-resolve ((instance debug-frame))
266285
(list (make-instance 'debug-local-scope
267286
:environment (jupyter:debug-object-environment instance)
268287
:parent instance)))
269288

270-
271289
(defmethod jupyter:debug-object-children-resolve ((instance debug-local-scope))
272290
(stable-sort
273291
#+ccl (let ((frame (jupyter:debug-object-data (jupyter:debug-object-parent instance))))

src/kernel.lisp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@
375375
(defgeneric debug-inspect-variables (kernel environment)
376376
(:documentation "Return a list of debug-objects represents the variables in the global scope."))
377377

378+
(defgeneric debug-modules (kernel)
379+
(:documentation "Return a list of debug-modules representing the modules available.")
380+
(:method (kernel)
381+
(declare (ignore kernel))
382+
nil))
378383

379384
(defclass debug-source ()
380385
((name
@@ -485,6 +490,18 @@
485490
:documentation "Implementation specific data associated with the object."))
486491
(:documentation "A debug object. Superclass of frames, scopes, variables, etc."))
487492

493+
(defclass debug-module (debug-object)
494+
((path
495+
:reader debug-object-path
496+
:initarg :path
497+
:type (or pathname string)
498+
:documentation "The path of the source."))
499+
(:documentation "A module in the debugger."))
500+
501+
(defmethod shasht:print-json-key-value :around ((object debug-module) key value output-stream)
502+
(when (member key '(id name path) :test #'equal)
503+
(let ((shasht:*symbol-name-function* #'symbol-to-camel-case))
504+
(call-next-method))))
488505

489506
(defmethod debug-object-children :before ((instance debug-object))
490507
(unless (slot-boundp instance 'children)
@@ -956,6 +973,8 @@
956973
(handle-debug-request/initialize))
957974
("debug_request/inspectVariables"
958975
(handle-debug-request/inspect-variables environment))
976+
("debug_request/modules"
977+
(handle-debug-request/modules))
959978
("debug_request/setBreakpoints"
960979
(handle-debug-request/set-breakpoints))
961980
("debug_request/source"
@@ -1195,6 +1214,21 @@
11951214

11961215
#|
11971216
1217+
### Message type: debug_request / modules ###
1218+
1219+
|#
1220+
1221+
(defun handle-debug-request/modules ()
1222+
(inform :info *kernel* "Handling debug_request/modules message")
1223+
(let ((modules (debug-modules *kernel*)))
1224+
(send-debug-reply
1225+
`(:object-plist
1226+
"modules" ,(or modules :empty-array)
1227+
"totalModules" ,(length modules))))
1228+
(send-status-idle))
1229+
1230+
#|
1231+
11981232
### Message type: debug_request / next ###
11991233
12001234
|#

src/packages.lisp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
#:debug-inspect-variables
7171
#:debug-new-breakpoint
7272
#:debug-next
73+
#:debug-module
74+
#:debug-modules
7375
#:debug-object
7476
#:debug-object-children
7577
#:debug-object-children-resolve

0 commit comments

Comments
 (0)