Browse Source

Make `indium-breakpoint-add' add breakpoints at point

workspaces
Nicolas Petton 3 years ago
parent
commit
dcfb56bfd4
Signed by: nico GPG Key ID: 233587A47C207910
3 changed files with 27 additions and 34 deletions
  1. +15
    -16
      indium-breakpoint.el
  2. +1
    -4
      indium-interaction.el
  3. +11
    -14
      test/unit/indium-breakpoint-test.el

+ 15
- 16
indium-breakpoint.el View File

@ -34,19 +34,21 @@
(eval-and-compile
(require 'indium-script))
(defun indium-breakpoint-add (location &optional condition)
"Add a breakpoint at LOCATION.
(defun indium-breakpoint-add (&optional condition)
"Add a breakpoint at point.
When CONDITION is non-nil, the breakpoint will be hit when
CONDITION is true."
(let* ((brk (make-indium-breakpoint :file (indium-location-file location)
:line (indium-location-line location)
:column (indium-location-column location)
:condition (or condition ""))))
(indium-breakpoint--add-overlay brk)
(when-indium-connected
(indium-backend-add-breakpoint (indium-current-connection-backend)
brk))))
(if-let ((location (indium-script-generated-location-at-point)))
(let* ((brk (make-indium-breakpoint :file (indium-location-file location)
:line (indium-location-line location)
:column (indium-location-column location)
:condition (or condition ""))))
(indium-breakpoint--add-overlay brk)
(when-indium-connected
(indium-backend-add-breakpoint (indium-current-connection-backend)
brk)))
(user-error "Cannot place a breakpoint here")))
(defun indium-breakpoint-edit-condition ()
"Edit condition of breakpoint at point."
@ -56,8 +58,7 @@ CONDITION is true."
old-condition nil nil nil old-condition)))
(setf (indium-breakpoint-condition breakpoint) new-condition)
(indium-breakpoint-remove)
(indium-breakpoint-add (indium-script-generated-location-at-point)
new-condition))))
(indium-breakpoint-add new-condition))))
(defun indium-breakpoint-remove ()
"Remove the breakpoint from the current line."
@ -174,8 +175,7 @@ An icon is added to the left fringe."
(lambda ()
(save-excursion
(goto-char start)
(indium-breakpoint-add (indium-script-generated-location-at-point)
(indium-breakpoint-condition brk)))))))))
(indium-breakpoint-add (indium-breakpoint-condition brk)))))))))
(defun indium-breakpoint--restore-breakpoints-in-current-buffer ()
"Restore all breakpoints set in the current buffer.
@ -186,8 +186,7 @@ This function is used when reconnecting to a new connection."
(when-let ((brk (overlay-get ov 'indium-breakpoint))
(start (overlay-start ov)))
(goto-char start)
(indium-breakpoint-add (indium-script-generated-location-at-point)
(indium-breakpoint-condition brk)))))))
(indium-breakpoint-add (indium-breakpoint-condition brk)))))))
(defun indium-breakpoint--fringe-icon ()
"Return the fringe icon used for breakpoints."


+ 1
- 4
indium-interaction.el View File

@ -37,7 +37,6 @@
(require 'indium-breakpoint)
(require 'indium-repl)
(require 'indium-render)
(require 'indium-script)
(declare-function indium-backend-activate-breakpoints "indium-backend.el")
(declare-function indium-backend-deactivate-breakpoints "indium-backend.el")
@ -135,9 +134,7 @@ When CONDITION is non-nil, add a conditional breakpoint with
CONDITION."
(interactive)
(indium-interaction--guard-no-breakpoint-at-point)
(if-let ((location (indium-script-generated-location-at-point)))
(indium-breakpoint-add location condition)
(user-error "Cannot place a breakpoint here")))
(indium-breakpoint-add condition))
(defun indium-add-conditional-breakpoint (condition)
"Add a breakpoint with CONDITION at point.


+ 11
- 14
test/unit/indium-breakpoint-test.el View File

@ -115,7 +115,7 @@
(with-js2-buffer "let a = 1;"
(goto-char (point-min))
(expect (indium-breakpoint-on-current-line-p) :to-be nil)
(indium-breakpoint-add (make-indium-location))
(indium-breakpoint-add)
(expect (indium-breakpoint-on-current-line-p) :to-be-truthy)))
(it "can edit a breakpoint on the current line"
@ -124,20 +124,18 @@
(spy-on #'indium-breakpoint-add :and-call-through)
(with-js2-buffer "let a = 1;"
(goto-char (point-min))
(let ((location (make-indium-location :file buffer-file-name
:line 0)))
(indium-breakpoint-add location "old condition")
(indium-breakpoint-edit-condition)
(expect #'read-from-minibuffer :to-have-been-called)
(expect #'indium-breakpoint-remove :to-have-been-called)
(expect #'indium-breakpoint-add :to-have-been-called-with location "new condition")))))
(indium-breakpoint-add "old condition")
(indium-breakpoint-edit-condition)
(expect #'read-from-minibuffer :to-have-been-called)
(expect #'indium-breakpoint-remove :to-have-been-called)
(expect #'indium-breakpoint-add :to-have-been-called-with "new condition"))))
(describe "Breakpoint duplication handling"
(it "can add a breakpoint multiple times on the same line without duplicating it"
(with-temp-buffer
(indium-breakpoint-add (make-indium-location))
(indium-breakpoint-add)
(let ((number-of-overlays (seq-length (overlays-in (point-min) (point-max)))))
(indium-breakpoint-add (make-indium-location))
(indium-breakpoint-add)
(expect (seq-length (overlays-in (point-min) (point-max))) :to-equal number-of-overlays)))))
(describe "Restoring breakpoints"
@ -146,15 +144,14 @@
(spy-on 'indium-breakpoint-add :and-call-through)
(with-js2-buffer "let a = 2;"
(goto-char (point-min))
(let ((loc (make-indium-location))
(condition "condition"))
(indium-breakpoint-add loc condition)
(let ((condition "condition"))
(indium-breakpoint-add condition)
;; simulate getting the breakpoint ID from a backend
(setf (indium-breakpoint-id (indium-breakpoint-at-point)) 'id)
(with-fake-indium-connection
(indium-breakpoint--restore-breakpoints-in-current-buffer)
(expect #'indium-backend-add-breakpoint :to-have-been-called)
(expect #'indium-breakpoint-add :to-have-been-called-with loc condition))))))
(expect #'indium-breakpoint-add :to-have-been-called-with condition))))))
(describe "Handling overlays in breakpoints"
(it "adding overlays should store the overlay in the breakpoint"


Loading…
Cancel
Save