Browse Source

Store overlays in breakpoints

workspaces
Nicolas Petton 4 years ago
parent
commit
66152001dd
Signed by: nico GPG Key ID: 233587A47C207910
4 changed files with 76 additions and 26 deletions
  1. +2
    -0
      indium-breakpoint.el
  2. +9
    -2
      indium-structs.el
  3. +38
    -8
      test/unit/indium-breakpoint-test.el
  4. +27
    -16
      test/unit/indium-structs-test.el

+ 2
- 0
indium-breakpoint.el View File

@ -124,11 +124,13 @@ An icon is added to the left fringe."
(overlay-put ov
'indium-breakpoint
breakpoint)
(setf (indium-breakpoint-overlay breakpoint) ov)
ov))
(defun indium-breakpoint--remove-overlay ()
"Remove the breakpoint overlay from the current line."
(let ((ov (indium-breakpoint--overlay-on-current-line)))
(setf (indium-breakpoint-overlay (overlay-get ov 'indium-breakpoint)) nil)
(remove-overlays (overlay-start ov)
(overlay-end ov)
'indium-breakpoint-ov


+ 9
- 2
indium-structs.el View File

@ -41,6 +41,7 @@
;;; Code:
(require 'map)
(require 'subr-x)
(declare-function indium-script-get-file "indium-script.el")
(declare-function indium-script-find-by-id "indium-script.el")
@ -150,7 +151,7 @@ If no such breakpoint exist, return nil."
If LINE is not provided, return all breakpoints in FILE."
(let ((breakpoints (map-values (indium-current-connection-breakpoints))))
(seq-filter (lambda (brk)
(and (string= (indium-breakpoint-local-file brk)
(and (string= (buffer-file-name (indium-breakpoint-buffer brk))
file)
(or (not line)
(= (indium-location-line
@ -215,17 +216,23 @@ If LINE is not provided, return all breakpoints in FILE."
(:constructor make-indium-breakpoint
(&key id
line
local-file
file
condition
overlay
&aux (location (make-indium-location
:line line
:file file)))))
(id nil :type string)
(overlay nil)
(local-file buffer-file-name :type string)
(location nil :type indium-location :read-only t)
(condition "" :type string))
(defun indium-breakpoint-buffer (breakpoint)
"Return the buffer in which BREAKPOINT is set, or nil."
(when-let ((ov (indium-breakpoint-overlay breakpoint)))
(overlay-buffer ov)))
(defun indium-breakpoint-file (breakpoint)
"Return the file for which BREAKPOINT is set."
(indium-location-file (indium-breakpoint-location breakpoint)))


+ 38
- 8
test/unit/indium-breakpoint-test.el View File

@ -29,7 +29,8 @@
(describe "Breakpoint position when editing buffers (GH issue #82)"
(it "should keep the breakpoint on the original line when adding a line before"
(with-js2-buffer "let a = true;"
(let ((ov (indium-breakpoint--ensure-overlay)))
(let* ((brk (make-indium-breakpoint))
(ov (indium-breakpoint--add-overlay brk)))
;; add a line before the current line with the breakpoint overlay
(goto-char (point-min))
(open-line 1)
@ -41,7 +42,8 @@
;; When inserting a line before, deleting a breakpoint resulted in an
;; overlay being added on the next line.
(with-js2-buffer "let a = true;"
(let ((ov (indium-breakpoint--ensure-overlay)))
(let* ((brk (make-indium-breakpoint))
(ov (indium-breakpoint--add-overlay brk)))
;; add a line before the current line with the breakpoint overlay
(goto-char (point-min))
(open-line 1)
@ -57,7 +59,8 @@
;; overlay being added on the next line when the line where the breakpoint
;; was added had been split.
(with-js2-buffer "let a = true;"
(let ((ov (indium-breakpoint--ensure-overlay)))
(let* ((brk (make-indium-breakpoint))
(ov (indium-breakpoint--add-overlay brk)))
;; add a line before the current line with the breakpoint overlay
(goto-char 5)
(newline)
@ -71,26 +74,30 @@
(describe "Making markers (tests for issue #79)"
(it "should put breakpoint overlays on the entire line"
(with-js2-buffer "let a = true;"
(let ((ov (indium-breakpoint--ensure-overlay)))
(let* ((brk (make-indium-breakpoint))
(ov (indium-breakpoint--add-overlay brk)))
(expect (overlay-start ov) :to-equal (point-at-bol))
(expect (overlay-end ov) :to-equal (point-at-eol)))))
(it "should be able to access breakpoints on empty lines"
(with-js2-buffer ""
(let ((ov (indium-breakpoint--ensure-overlay)))
(let* ((brk (make-indium-breakpoint))
(ov (indium-breakpoint--add-overlay brk)))
(expect (indium-breakpoint--overlay-on-current-line)
:to-be ov))))
(it "should be able to remove overlays on empty lines"
(with-js2-buffer ""
(indium-breakpoint--ensure-overlay)
(let ((brk (make-indium-breakpoint)))
(indium-breakpoint--add-overlay brk))
(expect (indium-breakpoint--overlay-on-current-line) :not :to-be nil)
(indium-breakpoint--remove-overlay)
(expect (indium-breakpoint--overlay-on-current-line) :to-be nil)))
(it "can get a breakpoint overlays on the current line when it changed"
(with-js2-buffer "let a = 1;"
(let ((ov (indium-breakpoint--ensure-overlay)))
(let* ((brk (make-indium-breakpoint))
(ov (indium-breakpoint--add-overlay brk)))
(goto-char (point-min))
(insert "\n")
(forward-line 1)
@ -99,7 +106,8 @@
(describe "Accessing breakpoints"
(it "can get a breakpoint overlays on the current line"
(with-js2-buffer "let a = 1;"
(let ((ov (indium-breakpoint--ensure-overlay)))
(let* ((brk (make-indium-breakpoint))
(ov (indium-breakpoint--add-overlay brk)))
(overlay-put ov 'indium-breakpoint t)
(expect (indium-breakpoint--overlay-on-current-line) :to-be ov))))
@ -148,5 +156,27 @@
(expect #'indium-backend-add-breakpoint :to-have-been-called)
(expect #'indium-breakpoint-add :to-have-been-called-with loc condition))))))
(describe "Handling overlays in breakpoints"
(it "adding overlays should store the overlay in the breakpoint"
(with-js2-buffer "let a = 2;"
(let* ((brk (make-indium-breakpoint))
(ov (indium-breakpoint--add-overlay brk)))
(expect (indium-breakpoint-overlay brk) :to-be ov))))
(it "removing overlays should remove them from breakpoints"
(with-js2-buffer "let a = 2;"
(let* ((brk (make-indium-breakpoint))
(ov (indium-breakpoint--add-overlay brk)))
(indium-breakpoint--remove-overlay)
(expect (indium-breakpoint-overlay brk) :to-be nil))))
(it "should access breakpoint buffers"
(with-js2-buffer "let a = 2;"
(let* ((brk (make-indium-breakpoint)))
(indium-breakpoint--add-overlay brk)
(expect (indium-breakpoint-buffer brk) :to-be (current-buffer))
(indium-breakpoint--remove-overlay)
(expect (indium-breakpoint-buffer brk) :to-be nil)))))
(provide 'indium-breakpoint-test)
;;; indium-breakpoint-test.el ends here

+ 27
- 16
test/unit/indium-structs-test.el View File

@ -25,7 +25,9 @@
;;; Code:
(require 'buttercup)
(require 'assess)
(require 'indium-structs)
(require 'cl-lib)
(describe "Setting current connection slots"
(it "should be able to set the frames"
@ -74,25 +76,34 @@
(it "can get breakpoints in a file"
(with-indium-connection (make-indium-connection)
(let ((brks (seq-map (lambda (data)
(apply #'make-indium-breakpoint data))
'((:id a :line 12 :local-file "foo.js" :file "foo.js" :condition "cond1")
(:id b :line 25 :local-file "foo.js" :file "foo.js" :condition "cond2")
(:id c :line 3 :local-file "bar.js" :file "bar.js" :condition "cond3")))))
(seq-do #'indium-current-connection-add-breakpoint brks)
(expect (indium-current-connection-get-breakpoints-in-file "foo.js") :to-equal
(list (car brks) (cadr brks))))))
(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)
(let ((brks (seq-map (lambda (data)
(apply #'make-indium-breakpoint data))
'((:id a :line 12 :local-file "foo.js" :file "foo.js" :condition "cond1")
(:id b :line 25 :local-file "foo.js" :file "foo.js" :condition "cond2")
(:id c :line 3 :local-file "bar.js" :file "bar.js" :condition "cond3")))))
(seq-do #'indium-current-connection-add-breakpoint brks)
(expect (indium-current-connection-get-breakpoints-in-file "foo.js" 25) :to-equal
(list (cadr brks))))))
(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 the file associated with a breakpoint"
(let ((brk (make-indium-breakpoint :file "foo.js")))


Loading…
Cancel
Save