Browse Source

Add breakpoint resolution handling

When a breakpoint is resolved by the runtime, update it.
Nicolas Petton 4 years ago
Signed by: nico GPG Key ID: 233587A47C207910
2 changed files with 44 additions and 2 deletions
  1. +25
  2. +19

+ 25
- 0
indium-breakpoint.el View File

@ -71,6 +71,16 @@ CONDITION is true."
(defun indium-breakpoint-resolve (id script location)
"Update the breakpoint with ID for SCRIPT at LOCATION.
This function should be called upon breakpoint resolution by the
backend, or when a breakpoint location gets updated from the
(let ((original-location (indium-script-original-location script location))
(brk (indium-current-connection-get-breakpoint id)))
(indium-breakpoint--update-overlay brk original-location)))
(defun indium-breakpoint-at-point ()
"Return the breakpoint on the current line.
If there is no breakpoint set on the line, return nil."
@ -136,6 +146,21 @@ An icon is added to the left fringe."
(defun indium-breakpoint--update-overlay (breakpoint location)
"Set the overlay for BREAKPOINT at LOCATION."
(when-let ((buf (indium-breakpoint-buffer breakpoint)))
(with-current-buffer buf
(goto-char (overlay-start (indium-breakpoint-overlay breakpoint)))
(when-let ((file (indium-location-file location))
(line (indium-location-line location)))
(with-current-buffer (find-file-noselect file)
(goto-char (point-min))
(forward-line line)
(indium-breakpoint--add-overlay breakpoint)))))
(defun indium-breakpoint--update-breakpoints-in-current-buffer ()
"Update the breakpoints for the current buffer in the backend."
(let ((overlays (overlays-in (point-min) (point-max))))

+ 19
- 2
indium-v8.el View File

@ -47,6 +47,7 @@
(require 'indium-debugger)
(require 'indium-workspace)
(require 'indium-script)
(require 'indium-breakpoint)
(defvar indium-v8-cache-disabled nil
"Network cache disabled state. If non-nil disable cache when Indium starts.")
@ -129,11 +130,16 @@ Evaluate CALLBACK on the filtered candidates."
(let* ((result (map-elt response 'result))
(id (map-elt result 'breakpointId))
(locations (map-elt result 'locations))
(line (map-elt (seq--elt-safe locations 0) 'lineNumber)))
(if line
(location (seq--elt-safe locations 0))
(line (map-elt location 'lineNumber)))
(if line
(setf (indium-breakpoint-id breakpoint) id)
(indium-current-connection-add-breakpoint breakpoint)
(let ((script (indium-script-find-by-id
(map-elt location 'scriptId)))
(location (indium-v8--convert-from-v8-location location)))
(indium-breakpoint-resolve id script location))
(when callback
(funcall callback breakpoint)))
(message "Cannot get breakpoint location")))))))
@ -350,10 +356,21 @@ If WORKSPACE is non-nil, make it the workspace used for the connection."
("Log.entryAdded" (indium-v8--handle-log-entry message))
("Runtime.consoleAPICalled" (indium-v8--handle-console-message message))
("Runtime.exceptionThrown" (indium-v8--handle-exception-thrown message))
("Debugger.breakpointResolved" (indium-v8--handle-breakpoint-resolved message))
("Debugger.paused" (indium-v8--handle-debugger-paused message))
("Debugger.scriptParsed" (indium-v8--handle-script-parsed message))
("Debugger.resumed" (indium-v8--handle-debugger-resumed message)))))))
(defun indium-v8--handle-breakpoint-resolved (message)
"Handle a breakpoint resolution.
MESSAGE contains the breakpoint id and location."
(let ((id (map-nested-elt message '(params breakpointId)))
(script (indium-script-find-by-id
(map-nested-elt message '(params location scriptId))))
(location (indium-v8--convert-from-v8-location
(map-nested-elt message '(params location)))))
(indium-breakpoint-resolve id script location)))
(defun indium-v8--handle-inspector-detached (message)
"Handle a closed connection event.
MESSAGE explains why the connection has been closed."