Browse Source

Remove breakpoint management from indium connections

Breakpoints are tracked with `indium-breakpoint--local-breakpoints' so there is
no need to put them in the current connection anymore.
workspaces
Nicolas Petton 3 years ago
parent
commit
2d510f084e
No known key found for this signature in database GPG Key ID: E8BCD7866AFCF978
7 changed files with 47 additions and 167 deletions
  1. +2
    -10
      indium-backend.el
  2. +16
    -21
      indium-breakpoint.el
  3. +20
    -18
      indium-interaction.el
  4. +0
    -53
      indium-structs.el
  5. +0
    -2
      indium-v8.el
  6. +9
    -1
      test/unit/indium-breakpoint-test.el
  7. +0
    -62
      test/unit/indium-structs-test.el

+ 2
- 10
indium-backend.el View File

@ -138,18 +138,10 @@ Evaluate CALLBACK on the filtered candidates.
EXPRESSION should be a valid JavaScript expression string.")
(cl-defgeneric indium-backend-register-breakpoint (backend breakpoint &optional callback)
"Request the addition of BREAKPOINT.
Concrete implementations should call
`indium-current-connection-add-breakpoint' once the addition has
been performed.")
"Request the addition of BREAKPOINT.")
(cl-defgeneric indium-backend-unregister-breakpoint (backend id &optional callback)
"Request the removal of the breakpoint with id ID.
Concrete implementations should call
`indium-current-connection-remove-breakpoint' once the removal
has been performed.")
"Request the removal of the breakpoint with id ID.")
(cl-defgeneric indium-backend-deactivate-breakpoints (backend)
"Deactivate all breakpoints.


+ 16
- 21
indium-breakpoint.el View File

@ -86,9 +86,15 @@ This function should be called upon breakpoint resolution by the
backend, or when a breakpoint location gets updated from the
backend."
(let ((original-location (indium-script-original-location script location))
(brk (indium-current-connection-get-breakpoint id)))
(brk (indium-breakpoint-breakpoint-with-id id)))
(indium-breakpoint--update-overlay brk original-location)))
(defun indium-breakpoint-breakpoint-with-id (id)
"Return the breakpoint with ID or nil."
(seq-find (lambda (brk)
(equal id (indium-breakpoint-id brk)))
(map-keys indium-breakpoint--local-breakpoints)))
(defun indium-breakpoint-at-point ()
"Return the breakpoint on the current line.
If there is no breakpoint set on the line, return nil."
@ -99,16 +105,6 @@ If there is no breakpoint set on the line, return nil."
"Return non-nil if there is a breakpoint on the current line."
(not (null (indium-breakpoint--overlay-on-current-line))))
(defun indium-breakpoint-add-breakpoints-to-buffer ()
"Add all breakpoints markers to the current buffer.
This function does not register breakpoints."
(seq-do (lambda (brk)
(save-excursion
(goto-char (point-min))
(forward-line (indium-location-line (indium-breakpoint-location brk)))
(indium-breakpoint--add-overlay brk)))
(indium-current-connection-get-breakpoints-in-file buffer-file-name)))
(defun indium-breakpoint-remove-overlays-from-current-buffer ()
"Remove all breakpoint markers from the current buffer.
This function does no unset breakpoints."
@ -189,11 +185,11 @@ When PRED is non-nil, only resolve breakpoints which
satisfy (PRED brk)."
(indium-breakpoint--breakpoints-in-buffer-do
(lambda (brk overlay)
(when (or (null pred)
(funcall pred brk))
(save-excursion
(goto-char (overlay-start overlay))
(indium-breakpoint-add (indium-breakpoint-condition brk)))))))
(when (and (indium-breakpoint-unresolved-p brk)
(or (null pred)
(funcall pred brk)))
(indium-backend-register-breakpoint (indium-current-connection-backend)
brk)))))
(defun indium-breakpoint--fringe-icon ()
"Return the fringe icon used for breakpoints."
@ -223,11 +219,10 @@ If there is no overlay, make one."
"Attempt to resolve unresolved breakpoints for SCRIPT."
(indium-breakpoint--resolve-all-breakpoints
(lambda (brk)
(and (indium-breakpoint-unresolved-p brk)
(eq script
(indium-script-find-from-file (indium-location-file
(indium-script-generated-location
(indium-breakpoint-location brk)))))))))
(eq script
(indium-script-find-from-file (indium-location-file
(indium-script-generated-location
(indium-breakpoint-location brk))))))))
;; Update/Restore breakpoints
(add-hook 'indium-update-script-source-hook #'indium-breakpoint--update-after-script-source-set)


+ 20
- 18
indium-interaction.el View File

@ -213,23 +213,31 @@ hitting a breakpoint."
(defun indium-list-breakpoints ()
"List all breakpoints in the current connection."
(interactive)
(xref--show-xrefs (indium--make-xrefs-from-breakpoints) nil))
(if-let ((xrefs (indium--make-xrefs-from-breakpoints)))
(xref--show-xrefs xrefs nil)
(message "No breakpoint")))
(defun indium--make-xrefs-from-breakpoints ()
"Return a list of xref objects from all breakpoints."
(map-values-apply (lambda (breakpoint)
(xref-make (indium--get-breakpoint-xref-match breakpoint)
(xref-make-file-location (map-elt breakpoint 'file)
(1+ (map-elt breakpoint 'line))
0)))
(indium-current-connection-breakpoints)))
(defun indium--get-breakpoint-xref-match (breakpoint)
(map-apply (lambda (breakpoint buffer)
(let ((line (with-current-buffer buffer
(line-number-at-pos
(overlay-start
(indium-breakpoint-overlay breakpoint))))))
(xref-make (indium--get-breakpoint-xref-match breakpoint buffer)
(xref-make-file-location (buffer-file-name buffer)
line
0))))
indium-breakpoint--local-breakpoints))
(defun indium--get-breakpoint-xref-match (breakpoint buffer)
"Return the source line where BREAKPOINT is set."
(with-current-buffer (find-file-noselect (map-elt breakpoint 'file))
(with-current-buffer buffer
(save-excursion
(goto-char (point-min))
(forward-line (map-elt breakpoint 'line))
(forward-line (1- (line-number-at-pos
(overlay-start
(indium-breakpoint-overlay breakpoint)))))
(buffer-substring (point-at-bol) (point-at-eol)))))
(defun indium-interaction-node-before-point ()
@ -317,15 +325,9 @@ hitting a breakpoint."
\\{indium-interaction-mode-map}"
:lighter " js-interaction"
:keymap indium-interaction-mode-map
(if indium-interaction-mode
(indium-interaction-mode-on)
(unless indium-interaction-mode
(indium-interaction-mode-off)))
(defun indium-interaction-mode-on ()
"Function to be evaluated when `indium-interaction-mode' is turned on."
(when-indium-connected
(indium-breakpoint-add-breakpoints-to-buffer)))
(defun indium-interaction-mode-off ()
"Function to be evaluated when `indium-interaction-mode' is turned off."
(indium-breakpoint-remove-overlays-from-current-buffer))


+ 0
- 53
indium-structs.el View File

@ -68,27 +68,11 @@
(process nil :type process)
(callbacks (make-hash-table) :type hash-table)
(scripts (make-hash-table) :type hash-table)
(breakpoints (make-hash-table :test #'equal) :type hash-table)
(frames nil :type list)
(current-frame nil :type indium-frame)
;; extra properties that can be added by the backend
(props (make-hash-table) :type hash-table))
(defun indium-connection-add-breakpoint (breakpoint connection)
"Add BREAKPOINT to the map of breakpoints in CONNECTION."
(map-put (indium-connection-breakpoints connection)
(indium-breakpoint-id breakpoint)
breakpoint))
(defun indium-connection-remove-breakpoint (id connection)
"Remove the breakpoint with ID from CONNECTION."
(map-delete (indium-connection-breakpoints connection) id))
(defun indium-connection-get-breakpoint (id connection)
"Return the breakpoint with ID in CONNECTION.
If no breakpoint with ID exist in CONNECTION, return nil."
(map-elt (indium-connection-breakpoints connection) id))
(defun indium-current-connection-backend ()
"Return the backend of the current connection if any."
(when-indium-connected
@ -122,43 +106,6 @@ If no breakpoint with ID exist in CONNECTION, return nil."
(when-indium-connected
(indium-connection-scripts indium-current-connection)))
(defun indium-current-connection-breakpoints ()
"Return the breakpoints of the current connection if any."
(when-indium-connected
(indium-connection-breakpoints indium-current-connection)))
(defun indium-current-connection-add-breakpoint (breakpoint)
"Add BREAKPOINT to the current connection.
Breakpoints are registered locally in the current connection so
that if a buffer later visits FILE with `indium-interaction-mode'
turned on, the breakpoint can be added back to the buffer."
(when-indium-connected
(indium-connection-add-breakpoint breakpoint indium-current-connection)))
(defun indium-current-connection-remove-breakpoint (id)
"Remove the breakpoint with ID from the current connection."
(when-indium-connected
(indium-connection-remove-breakpoint id indium-current-connection)))
(defun indium-current-connection-get-breakpoint (id)
"Return the breakpoint with ID in the current connection.
If no such breakpoint exist, return nil."
(indium-connection-get-breakpoint id indium-current-connection))
(defun indium-current-connection-get-breakpoints-in-file (file &optional line)
"Return all breakpoints in FILE at LINE.
If LINE is not provided, return all breakpoints in FILE."
(let ((breakpoints (map-values (indium-current-connection-breakpoints))))
(seq-filter (lambda (brk)
(and (string= (buffer-file-name (indium-breakpoint-buffer brk))
file)
(or (not line)
(= (indium-location-line
(indium-breakpoint-location brk))
line))))
breakpoints)))
(defun indium-current-connection-props ()
"Return the props of the current connection if any."
(when-indium-connected


+ 0
- 2
indium-v8.el View File

@ -134,7 +134,6 @@ Evaluate CALLBACK on the filtered candidates."
(location (seq--elt-safe locations 0))
(line (map-elt location 'lineNumber)))
(setf (indium-breakpoint-id breakpoint) id)
(indium-current-connection-add-breakpoint breakpoint)
(if line
(let ((script (indium-script-find-by-id
(map-elt location 'scriptId)))
@ -151,7 +150,6 @@ Evaluate CALLBACK on success"
`((method . "Debugger.removeBreakpoint")
(params . ((breakpointId . ,id))))
(lambda (_response)
(indium-current-connection-remove-breakpoint id)
(when callback (funcall callback)))))
(cl-defmethod indium-backend-deactivate-breakpoints ((_backend (eql v8)))


+ 9
- 1
test/unit/indium-breakpoint-test.el View File

@ -180,7 +180,15 @@
(let ((indium-breakpoint--local-breakpoints (make-hash-table :weakness t)))
(indium-breakpoint-add)
(kill-buffer)
(expect (seq-length (map-keys indium-breakpoint--local-breakpoints)) :to-be 0)))))
(expect (seq-length (map-keys indium-breakpoint--local-breakpoints)) :to-be 0))))
(it "can get breakpoints by id"
(let ((indium-breakpoint--local-breakpoints (make-hash-table))
(brk (make-indium-breakpoint :id 'foo)))
(map-put indium-breakpoint--local-breakpoints
brk
'bar)
(expect (indium-breakpoint-breakpoint-with-id 'foo) :to-be brk))))
(describe "Breakpoint resolution"
(it "should be able to unresolve breakpoints"


+ 0
- 62
test/unit/indium-structs-test.el View File

@ -67,67 +67,5 @@
(expect (indium-location-column (indium-breakpoint-location brk))
:to-equal 2))))
(describe "Manipulating breakpoints"
(it "can register breakpoints"
(with-indium-connection (make-indium-connection)
(expect (indium-current-connection-get-breakpoint 'a) :to-be nil)
(let ((brk (make-indium-breakpoint :id 'a :line 12 :file "foo.js" :condition "cond")))
(indium-current-connection-add-breakpoint brk)
(expect (indium-current-connection-get-breakpoint 'a) :to-be brk))))
(it "can get breakpoints in a file"
(with-indium-connection (make-indium-connection)
(assess-with-filesystem '("foo.js" "bar.js")
(let* ((bufs (seq-map #'find-file-noselect (seq-map #'expand-file-name '("foo.js" "bar.js"))))
(brks (seq-map (lambda (buf)
(with-current-buffer buf
(make-indium-breakpoint :id (symbol-name (cl-gensym))
:overlay (make-overlay (point) (point)))))
bufs)))
(seq-map #'indium-current-connection-add-breakpoint brks)
(message "%s" bufs)
(message "%s" (indium-current-connection-breakpoints))
(expect (indium-current-connection-get-breakpoints-in-file (expand-file-name "foo.js"))
:to-equal (list (car brks)))))))
(it "can get breakpoints in a file with line"
(with-indium-connection (make-indium-connection)
(assess-with-filesystem '("foo.js")
(let ((buf (find-file-noselect (expand-file-name "foo.js")))
(brks (list (make-indium-breakpoint :id 'a :file "foo.js" :line 5)
(make-indium-breakpoint :id 'a :file "foo.js" :line 6))))
(seq-do (lambda (brk)
(with-current-buffer buf
(goto-char (point-min))
(forward-line (1- (indium-location-line (indium-breakpoint-location brk))))
(indium-breakpoint--add-overlay brk)
(indium-current-connection-add-breakpoint brk)))
brks)
(expect (indium-current-connection-get-breakpoints-in-file (expand-file-name "foo.js") 6)
:to-equal (list (cadr brks)))))))
(it "can get breakpoint from ID"
(with-indium-connection (make-indium-connection)
(let ((brk (make-indium-breakpoint :id 'a :line 12 :file "foo.js" :condition "cond")))
(indium-current-connection-add-breakpoint brk)
(expect (indium-current-connection-get-breakpoint 'a) :to-be brk))))
(it "can know if a breakpoint is resolved"
(expect (indium-breakpoint-unresolved-p (make-indium-breakpoint)) :to-be-truthy)
(expect (indium-breakpoint-unresolved-p (make-indium-breakpoint :id 'fake)) :not :to-be-truthy))
(it "gets nil when no breakpoint found for ID"
(with-indium-connection (make-indium-connection)
(let ((brk (make-indium-breakpoint :id 'a :line 12 :file "foo.js" :condition "cond")))
(indium-current-connection-add-breakpoint brk)
(expect (indium-current-connection-get-breakpoint 'b) :to-equal nil))))
(it "can unregister breakpoints"
(with-indium-connection (make-indium-connection)
(let ((brk (make-indium-breakpoint :id 'a :line 12 :file "foo.js" :condition "cond")))
(indium-current-connection-add-breakpoint brk)
(indium-current-connection-remove-breakpoint 'a)
(expect (map-values (indium-current-connection-breakpoints)) :to-be nil)))))
(provide 'indium-structs-test)
;;; indium-structs-test.el ends here

Loading…
Cancel
Save