Browse Source

Fix linting warnings

workspaces
Nicolas Petton 3 years ago
parent
commit
cfc0bbbb26
Signed by: nico GPG Key ID: 233587A47C207910
10 changed files with 166 additions and 102 deletions
  1. +3
    -4
      indium-backend.el
  2. +5
    -5
      indium-breakpoint.el
  3. +53
    -44
      indium-debugger.el
  4. +11
    -4
      indium-inspector.el
  5. +11
    -1
      indium-interaction.el
  6. +1
    -1
      indium-nodejs.el
  7. +12
    -2
      indium-render.el
  8. +10
    -2
      indium-repl.el
  9. +55
    -36
      indium-webkit.el
  10. +5
    -3
      indium-workspace.el

+ 3
- 4
indium-backend.el View File

@ -28,7 +28,6 @@
(require 'map)
(require 'seq)
(require 'indium-repl)
(require 'indium-debugger-litable)
(declare 'indium-debugger-unset-current-buffer)
@ -84,14 +83,14 @@ The new connection is based on the current (usually closed) one."
;;; indium-connection methods
(cl-defgeneric indium-backend-active-connection-p (backend)
(cl-defgeneric indium-backend-active-connection-p (_backend)
"Return non-nil if the current connection is active."
t)
(cl-defgeneric indium-backend-close-connection (backend)
(cl-defgeneric indium-backend-close-connection (_backend)
"Close the current connection.")
(cl-defgeneric indium-backend-reconnect (backend)
(cl-defgeneric indium-backend-reconnect (_backend)
"Try to re-establish a connection.
The new connection is created based on the current
`indium-connection'.")


+ 5
- 5
indium-breakpoint.el View File

@ -39,11 +39,11 @@ CONDITION is true."
(let ((ov (indium-breakpoint--put-icon condition)))
(when indium-connection
(indium-backend-add-breakpoint (indium-backend)
buffer-file-name
(1- (line-number-at-pos))
(lambda (line id condition)
(indium-breakpoint-added id ov))
condition))))
buffer-file-name
(1- (line-number-at-pos))
(lambda (line id condition)
(indium-breakpoint-added id ov))
condition))))
(defun indium-breakpoint-remove ()
"Remove the breakpoint from the current line."


+ 53
- 44
indium-debugger.el View File

@ -55,14 +55,46 @@
#("." 0 1 (display (left-fringe right-triangle)))
"Used as an overlay's before-string prop to place a fringe arrow.")
(declare 'indium-backend-debugger-get-script-source)
(defvar indium-debugger-mode-map
(let ((map (make-sparse-keymap)))
(define-key map " " #'indium-debugger-step-over)
(define-key map (kbd "i") #'indium-debugger-step-into)
(define-key map (kbd "o") #'indium-debugger-step-out)
(define-key map (kbd "c") #'indium-debugger-resume)
(define-key map (kbd "l") #'indium-debugger-locals)
(define-key map (kbd "s") #'indium-debugger-stack-frames)
(define-key map (kbd "q") #'indium-debugger-resume)
(define-key map (kbd "h") #'indium-debugger-here)
(define-key map (kbd "e") #'indium-debugger-evaluate)
(define-key map (kbd "n") #'indium-debugger-next-frame)
(define-key map (kbd "p") #'indium-debugger-previous-frame)
map))
(define-minor-mode indium-debugger-mode
"Minor mode for debugging JS scripts.
\\{indium-debugger-mode-map}"
:group 'indium
:lighter " JS-debug"
:keymap indium-debugger-mode-map
(if indium-debugger-mode
(progn
(unless indium-interaction-mode
(indium-interaction-mode))
(add-hook 'pre-command-hook #'indium-debugger-refresh-echo-area nil t))
(remove-hook 'pre-command-hook #'indium-debugger-refresh-echo-area t)))
(defun indium-debugger-paused (frames &optional reason)
"Handle execution pause.
Setup the debugging stack FRAMES when the execution has paused.
If REASON is non-nil, display it in the echo area."
(indium-debugger-set-frames frames (car frames))
(indium-debugger-select-frame (car frames))
(indium-debugger-show-help-message reason))
(defun indium-debugger-resumed (&rest _args)
"Handle resumed execution.
Unset the debugging context and turn off indium-debugger-mode."
(message "Execution resumed")
(indium-debugger-unset-frames)
(seq-doseq (buf (seq-filter (lambda (buf)
@ -72,7 +104,14 @@
(with-current-buffer buf
(set-marker overlay-arrow-position nil (current-buffer))
(indium-debugger-remove-highlights)
(indium-debugger-litable-unset-buffer))))
(indium-debugger-litable-unset-buffer)))
(let ((locals-buffer (indium-debugger-locals-get-buffer))
(frames-buffer (indium-debugger-frames-get-buffer)))
(when locals-buffer (kill-buffer locals-buffer))
(when frames-buffer (kill-buffer frames-buffer))
(if buffer-file-name
(indium-debugger-unset-current-buffer)
(kill-buffer))))
(defun indium-debugger-next-frame ()
"Jump to the next frame in the frame stack."
@ -121,7 +160,7 @@ buffer visiting it."
"Setup the current buffer for debugging."
(when (buffer-modified-p)
(revert-buffer nil nil t))
(indium-debugger-position-buffer))
(indium-debugger--goto-current-frame))
(defun indium-debugger-setup-buffer-no-file (source)
"Setup the current buffer with the frame source SOURCE."
@ -130,9 +169,10 @@ buffer visiting it."
(let ((inhibit-read-only t))
(erase-buffer)
(insert source)))
(indium-debugger-position-buffer))
(indium-debugger--goto-current-frame))
(defun indium-debugger-position-buffer ()
(defun indium-debugger--goto-current-frame ()
"Move the point to the current stack frame position in the current buffer."
(let* ((frame (indium-debugger-current-frame))
(location (map-elt frame 'location))
(line (map-elt location 'lineNumber))
@ -188,12 +228,14 @@ buffer visiting it."
(message indium-debugger-message))
(defun indium-debugger-setup-overlay-arrow ()
"Setup the overlay pointing to the current debugging line."
(let ((pos (line-beginning-position)))
(setq overlay-arrow-string "=>")
(setq overlay-arrow-position (make-marker))
(set-marker overlay-arrow-position pos (current-buffer))))
(defun indium-debugger-highlight-node ()
"Highlight the current AST node where the execution has paused."
(let ((beg (point))
(end (line-end-position)))
(indium-debugger-remove-highlights)
@ -201,6 +243,7 @@ buffer visiting it."
'face 'indium-highlight-face)))
(defun indium-debugger-remove-highlights ()
"Remove all debugging highlighting overlays from the current buffer."
(remove-overlays (point-min) (point-max) 'face 'indium-highlight-face))
(defun indium-debugger-top-frame ()
@ -226,19 +269,13 @@ buffer visiting it."
(indium-backend-step-out (indium-backend)))
(defun indium-debugger-resume ()
"Request the runtime to resume the execution."
(interactive)
(indium-backend-resume (indium-backend) #'indium-debugger-resumed)
(let ((locals-buffer (indium-debugger-locals-get-buffer))
(frames-buffer (indium-debugger-frames-get-buffer)))
(when locals-buffer
(kill-buffer locals-buffer))
(when frames-buffer
(kill-buffer frames-buffer))
(if buffer-file-name
(indium-debugger-unset-current-buffer)
(kill-buffer))))
(indium-backend-resume (indium-backend) #'indium-debugger-resumed))
(defun indium-debugger-here ()
"Request the runtime to resume the execution until the point.
When the position of the point is reached, pause the execution."
(interactive)
(indium-backend-continue-to-location (indium-backend)
`((scriptId . ,(map-nested-elt (indium-debugger-top-frame)
@ -333,6 +370,7 @@ frame."
"*JS Debugger*")
(defun indium-debugger-setup-buffer (buffer)
"Setup BUFFER for debugging."
(with-current-buffer buffer
(unless (or buffer-file-name
(eq major-mode indium-debugger-major-mode))
@ -352,34 +390,5 @@ frame."
(read-only-mode -1)
(indium-debugger-litable-unset-buffer))
(defvar indium-debugger-mode-map
(let ((map (make-sparse-keymap)))
(define-key map " " #'indium-debugger-step-over)
(define-key map (kbd "i") #'indium-debugger-step-into)
(define-key map (kbd "o") #'indium-debugger-step-out)
(define-key map (kbd "c") #'indium-debugger-resume)
(define-key map (kbd "l") #'indium-debugger-locals)
(define-key map (kbd "s") #'indium-debugger-stack-frames)
(define-key map (kbd "q") #'indium-debugger-resume)
(define-key map (kbd "h") #'indium-debugger-here)
(define-key map (kbd "e") #'indium-debugger-evaluate)
(define-key map (kbd "n") #'indium-debugger-next-frame)
(define-key map (kbd "p") #'indium-debugger-previous-frame)
map))
(define-minor-mode indium-debugger-mode
"Minor mode for debugging JS scripts.
\\{indium-debugger-mode-map}"
:group 'indium
:lighter " JS-debug"
:keymap indium-debugger-mode-map
(if indium-debugger-mode
(progn
(unless indium-interaction-mode
(indium-interaction-mode))
(add-hook 'pre-command-hook #'indium-debugger-refresh-echo-area nil t))
(remove-hook 'pre-command-hook #'indium-debugger-refresh-echo-area t)))
(provide 'indium-debugger)
;;; indium-debugger.el ends here

+ 11
- 4
indium-inspector.el View File

@ -32,7 +32,8 @@
(defvar indium-inspector-history nil)
(make-variable-buffer-local 'indium-inspector-history)
(declare indium-backend-get-properties)
(declare-function indium-backend-get-properties "indium-backend.el")
(declare-function indium-backend "indium-backend.el")
(defun indium-inspector-inspect (reference)
"Open an inspector on the remote object REFERENCE."
@ -45,6 +46,7 @@
(message "Cannot inspect %S" (map-elt reference 'description)))))
(defun indium-inspector--inspect-properties (properties reference)
"Insert all PROPERTIES for the remote object REFERENCE."
(let ((buf (indium-inspector-get-buffer-create))
(inhibit-read-only t))
(with-current-buffer buf
@ -56,10 +58,8 @@
(indium-render-properties properties)))
(pop-to-buffer buf)))
(defun indium-inspector-keybinding (command)
(key-description (car (where-is-internal command))))
(defun indium-inspector-pop ()
"Go back in the history to the last object inspected."
(interactive)
(if (cdr indium-inspector-history)
(progn
@ -68,6 +68,8 @@
(message "No previous object to inspect")))
(defun indium-inspector-goto-reference (direction)
"Move point to the next object reference in DIRECTION.
DIRECTION can be either `next' or `previous'."
(let* ((delta (pcase direction
(`next 1)
(`previous -1)))
@ -88,24 +90,29 @@
(forward-char 1))))
(defun indium-inspector-next-reference ()
"Move the point to the next object reference."
(interactive)
(indium-inspector-goto-reference 'next))
(defun indium-inspector-previous-reference ()
"Move the point to the previous object reference."
(interactive)
(indium-inspector-goto-reference 'previous))
(defun indium-inspector-refresh ()
"Request new data to the backend and update the inspector buffer."
(interactive)
(when indium-inspector-history
(funcall #'indium-inspector-inspect (car indium-inspector-history))))
(defun indium-inspector-push-to-history (reference)
"Add REFERENCE to the inspected objects history."
(unless (string= (map-elt reference 'objectid)
(map-elt (car indium-inspector-history) 'objectid))
(push reference indium-inspector-history)))
(defun indium-inspector-get-buffer ()
"Return the inspector buffer, or nil if no inspector buffer exists."
(get-buffer (indium-inspector-buffer-name)))
(defun indium-inspector-get-buffer-create ()


+ 11
- 1
indium-interaction.el View File

@ -18,6 +18,11 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Minor mode for interacting with a JavaScript runtime. This mode provides
;; commands for managing breakpoints and evaluating code.
;;; Code:
(require 'js2-mode)
@ -30,6 +35,10 @@
(require 'indium-repl)
(require 'indium-render)
(declare-function indium-backend-activate-breakpoints "indium-backend.el")
(declare-function indium-backend-deactivate-breakpoints "indium-backend.el")
(declare-function indium-workspace-make-url "indium-workspace.el")
(defcustom indium-update-script-on-save nil
"When non-nil, update (hotswap) the script source with the contents of the buffer."
:type 'boolean
@ -107,7 +116,8 @@ If PRINT is non-nil, print the output into the current buffer."
(user-error "No REPL buffer open")))
(defun indium-toggle-breakpoint (arg)
"Add a breakpoint at point."
"Add a breakpoint at point.
With a prefix argument ARG, add a conditional breakpoint."
(interactive "P")
(if (indium-breakpoint-on-current-line-p)
(indium-breakpoint-remove)


+ 1
- 1
indium-nodejs.el View File

@ -54,7 +54,7 @@
(indium-nodejs--connect host port path))))
(defun indium-nodejs--connect (host port path)
"Ask the user for a tab in the list TABS and connects to it."
"Ask the user for a websocket url HOST:PORT/PATH and connects to it."
(let ((websocket-url (format "ws://%s:%s/%s" host port path))
(url (format "file://%s" default-directory)))
(indium-webkit--open-ws-connection url websocket-url t)))


+ 12
- 2
indium-render.el View File

@ -25,8 +25,12 @@
;;; Code:
(require 'indium-faces)
(require 'seq)
(require 'map)
(declare 'indium-backend-object-reference-p)
(declare-function indium-backend-object-reference-p "indium-backend.el")
(declare-function indium-debugger-frames-select-frame "indium-debugger.el")
(declare-function indium-inspector-inspect "indium-inspector.el")
(defun indium-render-values (values &optional separator)
"Render VALUES separated by SEPARATOR.
@ -54,6 +58,7 @@ with a link to an inspector on that object."
(buffer-string)))
(defun indium-render-description (value)
"Insert VALUE fontified as a description."
(let ((description (indium-description-string value)))
(insert
(propertize description
@ -61,6 +66,7 @@ with a link to an inspector on that object."
'rear-nonsticky '(font-lock-face)))))
(defun indium-render-keyword (string)
"Insert STRING as fontified as a keyword."
(insert
(propertize string
'font-lock-face 'indium-keyword-face
@ -132,6 +138,7 @@ definitions."
(insert preview))))
(defun indium-render-properties (properties)
"Insert all items in PROPERTIES sorted by name."
(seq-map #'indium-render-property
(seq-sort (lambda (p1 p2)
(string< (map-elt p1 'name)
@ -139,6 +146,9 @@ definitions."
properties)))
(defun indium-render-property (property &optional separator)
"Insert the remote reference PROPERTY as a value.
When SEPARATOR is non-nil, insert it after the property.
Otherwise, insert a newline."
(insert " " (map-elt property 'name) ": ")
(indium-render-value (map-elt property 'value))
(insert (or separator "\n")))
@ -166,7 +176,7 @@ definitions."
(funcall function)))
(defun indium-message (&rest args)
"Like `message', with font-locking for JavaScript."
"Display ARGS like `message', but fontified as JavaScript."
(let ((string (with-temp-buffer
(js-mode)
(insert (apply #'format args))


+ 10
- 2
indium-repl.el View File

@ -24,12 +24,20 @@
;;; Code:
(require 'company)
(require 'indium-render)
(require 'indium-faces)
(require 'indium-backend)
(require 'company)
(require 'map)
(require 'js)
(require 'subr-x)
(require 'ansi-color)
(declare-function indium-workspace-lookup-file-safe "indium-workspace.el")
(declare-function indium-inspector-inspect "indium-inspector.el")
(defgroup indium-repl nil
"Interaction with the REPL."
:prefix "indium-repl-"
@ -70,7 +78,7 @@
"*JS REPL*")
(defun indium-repl-setup-buffer (buffer)
"Setup the REPL BUFFER"
"Setup the REPL BUFFER."
(with-current-buffer buffer
(indium-repl-mode)
(indium-repl-setup-markers)


+ 55
- 36
indium-webkit.el View File

@ -48,16 +48,16 @@
(indium-register-backend 'webkit)
(cl-defmethod indium-backend-active-connection-p ((backend (eql webkit)))
(cl-defmethod indium-backend-active-connection-p ((_backend (eql webkit)))
"Return non-nil if the current connection is active."
(and indium-connection
(websocket-openp (map-elt indium-connection 'ws))))
(cl-defmethod indium-backend-close-connection ((backend (eql webkit)))
(cl-defmethod indium-backend-close-connection ((_backend (eql webkit)))
"Close the websocket associated with the current connection."
(websocket-close (map-elt indium-connection 'ws)))
(cl-defmethod indium-backend-reconnect ((backend (eql webkit)))
(cl-defmethod indium-backend-reconnect ((_backend (eql webkit)))
(let* ((url (map-elt indium-connection 'url))
(websocket-url (websocket-url (map-elt indium-connection 'ws))))
(indium-webkit--open-ws-connection url
@ -66,7 +66,7 @@
;; connection the first
#'indium-quit)))
(cl-defmethod indium-backend-evaluate ((backend (eql webkit)) string &optional callback)
(cl-defmethod indium-backend-evaluate ((_backend (eql webkit)) string &optional callback)
"Evaluate STRING then call CALLBACK.
CALLBACK is called with two arguments, the value returned by the
evaluation and non-nil if the evaluation threw an error."
@ -83,7 +83,7 @@ evaluation and non-nil if the evaluation threw an error."
(when callback
(indium-webkit--handle-evaluation-response response callback))))))
(cl-defmethod indium-backend-get-completions ((backend (eql webkit)) expression prefix callback)
(cl-defmethod indium-backend-get-completions ((_backend (eql webkit)) expression prefix callback)
"Get the completion candidates for EXPRESSION that match PREFIX.
Evaluate CALLBACK on the filtered candidates."
(let ((expression (indium-webkit--completion-expression expression)))
@ -94,12 +94,12 @@ Evaluate CALLBACK on the filtered candidates."
(lambda (response)
(indium-webkit--handle-completions-response response prefix callback)))))
(cl-defmethod indium-backend-add-breakpoint ((backend (eql webkit)) file line &optional callback condition)
(cl-defmethod indium-backend-add-breakpoint ((_backend (eql webkit)) file line &optional callback condition)
"Request the addition of a breakpoint.
The breakpoint is set at URL on line LINE. When CALLBACK is
non-nil, evaluate it with the breakpoint's location and id."
(let ((url (indium-workspace-make-url buffer-file-name)))
(let ((url (indium-workspace-make-url file)))
(unless url
(user-error "No URL for the current buffer. Setup an Indium workspace first"))
(indium-webkit--send-request
@ -113,13 +113,13 @@ non-nil, evaluate it with the breakpoint's location and id."
(locations (map-elt breakpoint 'locations))
(line (map-elt (seq--elt-safe locations 0) 'lineNumber)))
(when line
(indium-backend-register-breakpoint id line buffer-file-name))
(indium-backend-register-breakpoint id line file))
(when callback
(unless line
(message "Cannot get breakpoint location"))
(funcall callback line id condition)))))))
(cl-defgeneric indium-backend-remove-breakpoint ((backend (eql webkit)) id)
(cl-defgeneric indium-backend-remove-breakpoint ((_backend (eql webkit)) id)
"Request the removal of the breakpoint with id ID."
(indium-webkit--send-request
`((method . "Debugger.removeBreakpoint")
@ -127,21 +127,21 @@ non-nil, evaluate it with the breakpoint's location and id."
(lambda (_response)
(indium-backend-unregister-breakpoint id))))
(cl-defgeneric indium-backend-deactivate-breakpoints ((backend (eql webkit)))
(cl-defgeneric indium-backend-deactivate-breakpoints ((_backend (eql webkit)))
"Deactivate all breakpoints.
The runtime will not pause on any breakpoint."
(indium-webkit--send-request
`((method . "Debugger.setBreakpointsActive")
(params . ((active . :json-false))))))
(cl-defgeneric indium-backend-activate-breakpoints ((backend (eql webkit)))
(cl-defgeneric indium-backend-activate-breakpoints ((_backend (eql webkit)))
"Deactivate all breakpoints.
The runtime will not pause on any breakpoint."
(indium-webkit--send-request
`((method . "Debugger.setBreakpointsActive")
(params . ((active . t))))))
(cl-defmethod indium-backend-get-properties ((backend (eql webkit)) reference &optional callback all-properties)
(cl-defmethod indium-backend-get-properties ((_backend (eql webkit)) reference &optional callback all-properties)
"Get the properties of the remote object represented by REFERENCE.
CALLBACK is evaluated with the list of properties.
@ -157,58 +157,58 @@ prototype chain of the remote object."
(indium-webkit--properties
(map-nested-elt response '(result result)))))))
(cl-defmethod indium-backend-set-script-source ((backend (eql webkit)) url source &optional callback)
(cl-defmethod indium-backend-set-script-source ((_backend (eql webkit)) url source &optional callback)
(when-let ((script-id (indium-webkit--get-script-id url)))
(indium-webkit--send-request
`((method . "Runtime.compileScript")
(params . ((expression . ,source)
(sourceURL . ,url)
(persistScript . :json-false))))
(lambda (response)
(lambda (_)
(indium-webkit--send-request
`((method . "Debugger.setScriptSource")
(params . ((scriptId . ,script-id)
(scriptSource . ,source))))
(lambda (response)
(lambda (_)
(when callback
(funcall callback))))))))
(cl-defmethod indium-backend-get-script-source ((backend (eql webkit)) frame callback)
(cl-defmethod indium-backend-get-script-source ((_backend (eql webkit)) frame callback)
(let ((script-id (map-nested-elt frame '(location scriptId))))
(indium-webkit--send-request
`((method . "Debugger.getScriptSource")
(params . ((scriptId . ,script-id))))
callback)))
(cl-defmethod indium-backend-get-script-url ((backend (eql webkit)) frame)
(cl-defmethod indium-backend-get-script-url ((_backend (eql webkit)) frame)
(let ((script-id (map-nested-elt frame '(location scriptId))))
(when script-id (indium-webkit--get-script-url script-id))))
(cl-defmethod indium-backend-resume ((backend (eql webkit)) &optional callback)
(cl-defmethod indium-backend-resume ((_backend (eql webkit)) &optional callback)
"Resume the debugger and evaluate CALLBACK if non-nil."
(indium-webkit--send-request
`((method . "Debugger.resume"))
callback))
(cl-defmethod indium-backend-step-into ((backend (eql webkit)) &optional callback)
(cl-defmethod indium-backend-step-into ((_backend (eql webkit)) &optional callback)
"Step into the current stack frame and evaluate CALLBACK if non-nil."
(indium-webkit--send-request
`((method . "Debugger.stepInto"))
callback))
(cl-defmethod indium-backend-step-out ((backend (eql webkit)) &optional callback)
(cl-defmethod indium-backend-step-out ((_backend (eql webkit)) &optional callback)
"Step out the current stack frame and evaluate CALLBACK if non-nil."
(indium-webkit--send-request
`((method . "Debugger.stepOut"))
callback))
(cl-defmethod indium-backend-step-over ((backend (eql webkit)) &optional callback)
(cl-defmethod indium-backend-step-over ((_backend (eql webkit)) &optional callback)
"Step over the current stack frame and evaluate CALLBACK if non-nil."
(indium-webkit--send-request
`((method . "Debugger.stepOver"))
callback))
(cl-defmethod indium-backend-continue-to-location ((backend (eql webkit)) location &optional callback)
(cl-defmethod indium-backend-continue-to-location ((_backend (eql webkit)) location &optional callback)
"Continue to LOCATION and evaluate CALLBACK if non-nil.
Location should be an alist with a `limeNumber' and `scriptId' key."
@ -285,7 +285,7 @@ If NODEJS is non-nil, add a `nodejs' flag to the
:on-close #'indium-webkit--handle-ws-closed
:on-error #'indium-webkit--handle-ws-error))
(defun indium-webkit--make-connection (ws url nodejs)
(defun indium-webkit--make-connection (ws url &optional nodejs)
"Return a new connection for WS and URL.
If NODEJS is non-nil, add a `nodejs' flag to the connection."
(let ((connection (make-hash-table)))
@ -301,13 +301,18 @@ If NODEJS is non-nil, add a `nodejs' flag to the connection."
"Return the callbacks associated with the current connection."
(map-elt indium-connection 'callbacks))
(defun indium-webkit--handle-ws-open (ws url)
(setq indium-connection (indium-webkit--make-connection ws url))
(defun indium-webkit--handle-ws-open (ws url nodejs)
"Setup indium for a new connection for the websocket WS.
URL points to the browser tab.
If NODEJS is non-nil, set a flag in the connection."
(setq indium-connection (indium-webkit--make-connection ws url nodejs))
(indium-webkit--enable-tools)
(switch-to-buffer (indium-repl-buffer-create))
(indium-breakpoint-restore-breakpoints))
(defun indium-webkit--handle-ws-message (ws frame)
(defun indium-webkit--handle-ws-message (_ws frame)
"Handle a websocket message FRAME."
(let* ((message (indium-webkit--read-ws-message frame))
(error (map-elt message 'error))
(method (map-elt message 'method))
@ -327,29 +332,33 @@ If NODEJS is non-nil, add a `nodejs' flag to the connection."
("Debugger.resumed" (indium-webkit--handle-debugger-resumed message)))))))
(defun indium-webkit--handle-inspector-detached (message)
"Handle closed connection.
"Handle a closed connection event.
MESSAGE explains why the connection has been closed."
(let ((msg (map-nested-elt message '(params reason))))
(indium-backend-close-connection 'webkit)
(message "Indium connection closed: %s" msg)))
(defun indium-webkit--handle-log-entry (message)
"Handle a log entry event with MESSAGE."
(let ((entry (map-nested-elt message '(params entry))))
;; unify console message and entry logs
(map-put entry 'line (map-elt entry 'lineNumber))
(indium-repl-emit-console-message entry)))
(defun indium-webkit--handle-console-message (message)
"Handle a console message event with MESSAGE."
(let* ((msg (map-elt message 'params))
(args (map-elt msg 'args)))
(setf (map-elt msg 'values) (seq-map #'indium-webkit--value args))
(indium-repl-emit-console-message msg)))
(defun indium-webkit--handle-exception-thrown (message)
"Handle an exception event MESSAGE."
(let ((exception (map-nested-elt message '(params exceptionDetails))))
(indium-repl-emit-console-message (indium-webkit--exception exception) t)))
(defun indium-webkit--handle-debugger-paused (message)
"Handle a debugger paused event with MESSAGE."
(let* ((frames (map-nested-elt message '(params callFrames)))
(exception (equal (map-nested-elt message '(params reason)) "exception"))
(reason (if exception "Exception occured" "Breakpoint hit")))
@ -358,20 +367,25 @@ MESSAGE explains why the connection has been closed."
(indium-debugger-paused (indium-webkit--frames frames) reason)))
(defun indium-webkit--handle-debugger-resumed (_message)
"Handle a runtime execution resumed event."
(unless (map-elt indium-connection 'nodejs)
(indium-webkit-remove-overlay-message))
(indium-debugger-resumed))
(defun indium-webkit--handle-script-parsed (message)
"Handle a script parsed event with MESSAGE."
(let* ((scriptId (map-nested-elt message '(params scriptId)))
(url (map-nested-elt message '(params url))))
(indium-webkit--add-script-parsed scriptId url)))
(defun indium-webkit--handle-ws-closed (_ws)
"Cleanup function called when the connection socket is closed."
(indium-repl--handle-connection-closed))
(defun indium-webkit--handle-ws-error (ws action error)
(message "WS Error! %s %s" action error))
(defun indium-webkit--handle-ws-error (_ws _action error)
"Display an error message for an exception in a websocket callback handling.
ERROR should be a description of the exception."
(message "Exception in websocket callback! %s" error))
(defun indium-webkit--send-request (request &optional callback)
"Send REQUEST to the current connection.
@ -388,6 +402,7 @@ If the current connection is closed, display a message."
(message "Socket connection closed")))
(defun indium-webkit--read-ws-message (frame)
"Parse the payload from the websocket FRAME."
(json-read-from-string (websocket-frame-payload frame)))
(defun indium-webkit--enable-tools ()
@ -418,7 +433,7 @@ inspectors."
(defun indium-webkit--enable-network ()
"Enable the runtime on the current tab."
(indium-webkit--send-request '((method . "Network.enable"))
(lambda (res)
(lambda (_)
(when indium-webkit-cache-disabled
(indium-webkit--set-cache-disabled t)))))
@ -480,8 +495,8 @@ arrays)."
"this"))
(defun indium-webkit--handle-completion-list-response (response prefix callback)
"Evauate CALLBACK on the completion candidates from RESPONSE.
Candidates are filtered using the PREFIX string."
"Filter candidates from RESPONSE matching PREFIX.
Evaluate CALLBACK on the result."
(let ((candidates (map-nested-elt response '(result result value))))
(funcall callback (seq-filter (lambda (candidate)
(string-prefix-p prefix candidate))
@ -588,6 +603,7 @@ RESULT should be a reference to a remote object."
list))
(defun indium-webkit--add-script-parsed (scriptId url)
"Add a parsed script from the runtime with id SCRIPTID at URL."
(unless (map-elt indium-connection 'scripts)
(map-put indium-connection 'scripts '()))
(map-put (map-elt indium-connection 'scripts)
@ -595,19 +611,22 @@ RESULT should be a reference to a remote object."
url))
(defun indium-webkit--get-script-url (scriptId)
"Lookup the parsed script with id SCRIPTID.
If no such script has been parsed, return nil."
(map-nested-elt indium-connection (list 'scripts (intern scriptId))))
(defun indium-webkit--get-script-id (url)
"Lookup the parsed script id for URL."
(seq-find #'identity
(map-apply (lambda (key val)
(when (string= url val)
(symbol-name key)))
(map-elt indium-connection 'scripts))))
(let ((id 0))
(defun indium-webkit--next-request-id ()
"Return the next unique identifier to be used in a request."
(cl-incf id)))
(defvar indium--request-id 0)
(defun indium-webkit--next-request-id ()
"Return the next unique identifier to be used in a request."
(cl-incf indium--request-id))
(provide 'indium-webkit)
;;; indium-webkit.el ends here

+ 5
- 3
indium-workspace.el View File

@ -51,6 +51,8 @@
(require 'map)
(require 'subr-x)
(require 'indium-backend)
(defun indium-workspace-lookup-file (url)
"Return a local file matching URL for the current connection.
If no file is found, return nil."
@ -63,7 +65,7 @@ If no file is found, return nil."
(or (indium-workspace-lookup-file url) url))
(defun indium-workspace--lookup-using-file-protocol (url)
"Return a local file matching URL if URL uses the file:// protocol."
"Return a local file matching URL if URL use the file:// protocol."
(when (indium-workspace--file-protocol-p)
(let* ((url (url-generic-parse-url url))
(path (car (url-path-and-query url))))
@ -86,7 +88,7 @@ If no file is found, return nil."
(indium-workspace--make-url-using-workspace file)))
(defun indium-workspace--make-url-using-file-protocol (file)
"If the current connection uses the file protocol, return FILE."
"If the current connection use the file protocol, return FILE."
(when (indium-workspace--file-protocol-p)
(format "file://%s" file)))
@ -100,7 +102,7 @@ The url is built using `indium-workspace-root'."
(url-recreate-url url))))
(defun indium-workspace--file-protocol-p ()
"Return non-nil if the current connection uses the file protocol."
"Return non-nil if the current connection use the file protocol."
(let ((url (url-generic-parse-url (map-elt indium-connection 'url))))
(string= (url-type url) "file")))


Loading…
Cancel
Save