Browse Source

Rename indium-connection to indium-current-connection

workspaces
Nicolas Petton 3 years ago
parent
commit
48525c2bf5
Signed by: nico GPG Key ID: 233587A47C207910
14 changed files with 59 additions and 59 deletions
  1. +13
    -13
      indium-backend.el
  2. +3
    -3
      indium-breakpoint.el
  3. +2
    -2
      indium-chrome.el
  4. +6
    -6
      indium-debugger.el
  5. +3
    -3
      indium-interaction.el
  6. +2
    -2
      indium-nodejs.el
  7. +2
    -2
      indium-repl.el
  8. +1
    -1
      indium-scratch.el
  9. +6
    -6
      indium-script.el
  10. +13
    -13
      indium-webkit.el
  11. +3
    -3
      indium-workspace.el
  12. +2
    -2
      test/integration/indium-nodejs-integration-test.el
  13. +2
    -2
      test/test-helper.el
  14. +1
    -1
      test/unit/indium-webkit-test.el

+ 13
- 13
indium-backend.el View File

@ -47,7 +47,7 @@
:group 'indium-backend
:type 'hook)
(defvar indium-connection nil
(defvar indium-current-connection nil
"Current connection to the browser tab.
A connection should be an alist with the following required keys:
@ -58,7 +58,7 @@ by backends.")
(defun indium-backend ()
"Return the backend for the current connection."
(map-elt indium-connection 'backend))
(map-elt indium-current-connection 'backend))
(defun indium-register-backend (backend)
"Register a new BACKEND.
@ -69,20 +69,20 @@ BACKEND should be a symbol."
"Close the current connection and kill its REPL buffer if any.
When called interactively, prompt for a confirmation first."
(interactive)
(unless indium-connection
(unless indium-current-connection
(user-error "No active connection to close"))
(when (or (not (called-interactively-p 'interactive))
(y-or-n-p (format "Do you really want to close the connection to %s ? "
(map-elt indium-connection 'url))))
(map-elt indium-current-connection 'url))))
(indium-backend-close-connection (indium-backend))
(indium-backend-cleanup-buffers)
(setq indium-connection nil)))
(setq indium-current-connection nil)))
(defun indium-reconnect ()
"Try to re-establish a connection.
The new connection is based on the current (usually closed) one."
(interactive)
(unless indium-connection
(unless indium-current-connection
(user-error "No Indium connection to reconnect to"))
(indium-backend-reconnect (indium-backend)))
@ -111,7 +111,7 @@ The new connection is based on the current (usually closed) one."
(cl-defgeneric indium-backend-reconnect (_backend)
"Try to re-establish a connection.
The new connection is created based on the current
`indium-connection'.")
`indium-current-connection'.")
(cl-defgeneric indium-backend-evaluate (backend string &optional callback)
"Evaluate STRING then call CALLBACK.
@ -160,23 +160,23 @@ performed.")
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 (and indium-connection
(null (map-elt indium-connection 'breakpoints)))
(map-put indium-connection 'breakpoints (make-hash-table)))
(when (and indium-current-connection
(null (map-elt indium-current-connection 'breakpoints)))
(map-put indium-current-connection 'breakpoints (make-hash-table)))
(let ((breakpoint `((line . ,line)
(file . ,file)
(condition . ,condition))))
(map-put (map-elt indium-connection 'breakpoints) id breakpoint)))
(map-put (map-elt indium-current-connection 'breakpoints) id breakpoint)))
(defun indium-backend-unregister-breakpoint (id)
"Remove the breakpoint with ID from the current connection."
(map-delete (map-elt indium-connection 'breakpoints) id))
(map-delete (map-elt indium-current-connection 'breakpoints) id))
(defun indium-backend-get-breakpoints ()
"Return all breakpoints in the current connection.
A breakpoint is an alist with the keys `id', `file', `line' and
`condition'."
(let ((breakpoints (map-elt indium-connection 'breakpoints)))
(let ((breakpoints (map-elt indium-current-connection 'breakpoints)))
(map-keys-apply (lambda (key)
`((id . ,key)
(file . ,(map-nested-elt breakpoints `(,key file)))


+ 3
- 3
indium-breakpoint.el View File

@ -38,7 +38,7 @@
When CONDITION is non-nil, the breakpoint will be hit when
CONDITION is true."
(let ((ov (indium-breakpoint--put-icon condition)))
(when indium-connection
(when indium-current-connection
(indium-backend-add-breakpoint (indium-backend)
location
(lambda (id)
@ -63,7 +63,7 @@ CONDITION is true."
(defun indium-breakpoint-remove ()
"Remove the breakpoint from the current line."
(if-let ((id (indium-breakpoint-id-at-point)))
(when indium-connection
(when indium-current-connection
(indium-backend-remove-breakpoint (indium-backend) id)))
(indium-breakpoint--remove-icon))
@ -96,7 +96,7 @@ This function does no unset breakpoints,"
(defun indium-breakpoint-update-breakpoints ()
"Update all breakpoints for the current buffer in the backend."
(when indium-connection
(when indium-current-connection
(indium-backend-remove-all-breakpoints-from-buffer (current-buffer))
(indium-breakpoint-restore-breakpoints)))


+ 2
- 2
indium-chrome.el View File

@ -94,9 +94,9 @@ Try a maximum of NUM-TRIES."
(defun indium-connect-to-chrome ()
"Open a connection to a webkit tab."
(interactive)
(when (or (null indium-connection)
(when (or (null indium-current-connection)
(yes-or-no-p "This requires closing the current connection. Are you sure? "))
(when indium-connection
(when indium-current-connection
(indium-quit))
(let ((host (read-from-minibuffer "Host: " "127.0.0.1"))
(port (read-from-minibuffer "Port: " (number-to-string indium-chrome-port))))


+ 6
- 6
indium-debugger.el View File

@ -313,25 +313,25 @@ Evaluation happens in the context of the current call frame."
(defun indium-debugger-set-frames (frames)
"Set the debugger FRAMES."
(map-put indium-connection 'frames frames)
(map-put indium-current-connection 'frames frames)
(indium-debugger-set-current-frame (car frames)))
(defun indium-debugger-set-current-frame (frame)
"Set FRAME as the current frame."
(map-put indium-connection 'current-frame frame))
(map-put indium-current-connection 'current-frame frame))
(defun indium-debugger-unset-frames ()
"Remove debugging information from the current connection."
(setq indium-connection (map-delete indium-connection 'frames))
(setq indium-connection (map-delete indium-connection 'current-frame)))
(setq indium-current-connection (map-delete indium-current-connection 'frames))
(setq indium-current-connection (map-delete indium-current-connection 'current-frame)))
(defun indium-debugger-current-frame ()
"Return the current debugged stack frame."
(map-elt indium-connection 'current-frame))
(map-elt indium-current-connection 'current-frame))
(defun indium-debugger-frames ()
"Return all frames in the current stack."
(map-elt indium-connection 'frames))
(map-elt indium-current-connection 'frames))
(defun indium-debugger-get-current-scopes ()
"Return the scope of the current stack frame."


+ 3
- 3
indium-interaction.el View File

@ -219,7 +219,7 @@ hitting a breakpoint."
(defun indium-interaction--ensure-connection ()
"Signal an error if there is no indium connection."
(unless indium-connection
(unless indium-current-connection
(user-error "No Indium connection")))
(defvar indium-interaction-mode-map
@ -269,7 +269,7 @@ hitting a breakpoint."
(defun indium-interaction-mode-on ()
"Function to be evaluated when `indium-interaction-mode' is turned on."
(when indium-connection
(when indium-current-connection
(indium-breakpoint-add-breakpoints-to-buffer)))
(defun indium-interaction-mode-off ()
@ -278,7 +278,7 @@ hitting a breakpoint."
(defun indium-interaction-update ()
"Update breakpoints and script source of the current buffer."
(when (and indium-interaction-mode indium-connection)
(when (and indium-interaction-mode indium-current-connection)
(indium-breakpoint-update-breakpoints)
(when indium-update-script-on-save
(indium-update-script-source))))


+ 2
- 2
indium-nodejs.el View File

@ -72,9 +72,9 @@ When the process is ready, open an Indium connection on it."
(defun indium-nodejs--connect (host port path)
"Ask the user for a websocket url HOST:PORT/PATH and connects to it."
(when (or (null indium-connection)
(when (or (null indium-current-connection)
(yes-or-no-p "This requires closing the current connection. Are you sure? "))
(when indium-connection
(when indium-current-connection
(indium-quit))
(let ((websocket-url (format "ws://%s:%s/%s" host port path))
(url (format "file://%s" default-directory)))


+ 2
- 2
indium-repl.el View File

@ -111,8 +111,8 @@ Doing this will also close all inspectors and debugger buffers
connected to the process.
")
(map-elt indium-connection 'backend)
(map-elt indium-connection 'url)))
(map-elt indium-current-connection 'backend)
(map-elt indium-current-connection 'url)))
(defun indium-repl-setup-markers ()


+ 1
- 1
indium-scratch.el View File

@ -39,7 +39,7 @@ one first."
If no buffer exists, create one.
If there is no current connection, throw an error."
(unless indium-connection
(unless indium-current-connection
(user-error "No current connection"))
(let* ((bufname (indium-scratch-buffer-name))
(buf (get-buffer bufname)))


+ 6
- 6
indium-script.el View File

@ -48,9 +48,9 @@
(defun indium-script-add-script-parsed (id url &optional sourcemap-url)
"Add a parsed script from the runtime with ID at URL.
If SOURCEMAP-URL is non-nil, add it to the parsed script."
(unless (map-elt indium-connection 'scripts)
(map-put indium-connection 'scripts '()))
(map-put (map-elt indium-connection 'scripts)
(unless (map-elt indium-current-connection 'scripts)
(map-put indium-current-connection 'scripts '()))
(map-put (map-elt indium-current-connection 'scripts)
(intern id)
(make-indium-script :id id
:url url
@ -59,7 +59,7 @@ If SOURCEMAP-URL is non-nil, add it to the parsed script."
(defun indium-script-find-by-id (id)
"Return the parsed script with id ID in the current connection.
If not such script was parsed, return nil."
(map-elt (map-elt indium-connection 'scripts) (intern id)))
(map-elt (map-elt indium-current-connection 'scripts) (intern id)))
(defun indium-script-get-file (script)
"Lookup the local file associated with SCRIPT.
@ -73,7 +73,7 @@ Return nil if no script can be found."
(map-apply (lambda (_id script)
(when (string= url (indium-script-url script))
script))
(map-elt indium-connection 'scripts))))
(map-elt indium-current-connection 'scripts))))
(defun indium-script-find-from-file (file)
"Lookup a script from a local FILE.
@ -88,7 +88,7 @@ Return nil if no script can be found."
(defun indium-script-all-scripts-with-sourcemap ()
"Return all parsed scripts that contain a sourcemap."
(seq-filter #'indium-script-has-sourcemap-p
(map-values (map-elt indium-connection 'scripts))))
(map-values (map-elt indium-current-connection 'scripts))))
(defun indium-script-sourcemap-file (script)
"Return the local sourcemap file associated with SCRIPT.


+ 13
- 13
indium-webkit.el View File

@ -51,16 +51,16 @@
(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))))
(and indium-current-connection
(websocket-openp (map-elt indium-current-connection 'ws))))
(cl-defmethod indium-backend-close-connection ((_backend (eql webkit)))
"Close the websocket associated with the current connection."
(websocket-close (map-elt indium-connection 'ws)))
(websocket-close (map-elt indium-current-connection 'ws)))
(cl-defmethod indium-backend-reconnect ((_backend (eql webkit)))
(let* ((url (map-elt indium-connection 'url))
(websocket-url (websocket-url (map-elt indium-connection 'ws))))
(let* ((url (map-elt indium-current-connection 'url))
(websocket-url (websocket-url (map-elt indium-current-connection 'ws))))
(indium-webkit--open-ws-connection url
websocket-url
;; close all buffers related to the closed
@ -71,7 +71,7 @@
"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."
(let* ((current-frame (map-elt indium-connection 'current-frame))
(let* ((current-frame (map-elt indium-current-connection 'current-frame))
(callFrameId (and current-frame (indium-frame-id current-frame))))
(indium-webkit--send-request
`((method . ,(if callFrameId
@ -272,7 +272,7 @@ In a Chrom{e|ium} session, URL corresponds to the url of a tab,
and WEBSOCKET-URL to its associated `webSocketDebuggerUrl'.
If NODEJS is non-nil, add a `nodejs' flag to the
`indium-connection' to handle special cases.
`indium-current-connection' to handle special cases.
If WORKSPACE is non-nil, make it the workspace directory for that
connection."
@ -301,7 +301,7 @@ If NODEJS is non-nil, add a `nodejs' flag to the connection."
(defun indium-webkit--callbacks ()
"Return the callbacks associated with the current connection."
(map-elt indium-connection 'callbacks))
(map-elt indium-current-connection 'callbacks))
(defun indium-webkit--handle-ws-open (ws url nodejs workspace)
"Setup indium for a new connection for the websocket WS.
@ -309,7 +309,7 @@ URL points to the browser tab.
If NODEJS is non-nil, set a flag in the connection.
If WORKSPACE is non-nil, make it the workspace used for the connection."
(setq indium-connection (indium-webkit--make-connection ws url nodejs))
(setq indium-current-connection (indium-webkit--make-connection ws url nodejs))
(indium-webkit--enable-tools)
(switch-to-buffer (indium-repl-buffer-create))
(when workspace (cd workspace))
@ -368,13 +368,13 @@ MESSAGE explains why the connection has been closed."
(exception (equal (map-nested-elt message '(params reason)) "exception"))
(reason (if exception "Exception occured" "Breakpoint hit"))
(description (map-nested-elt message '(params data description))))
(unless (map-elt indium-connection 'nodejs)
(unless (map-elt indium-current-connection 'nodejs)
(indium-webkit-set-overlay-message "Paused in Emacs debugger"))
(indium-debugger-paused (indium-webkit--frames frames) reason description)))
(defun indium-webkit--handle-debugger-resumed (_message)
"Handle a runtime execution resumed event."
(unless (map-elt indium-connection 'nodejs)
(unless (map-elt indium-current-connection 'nodejs)
(indium-webkit-remove-overlay-message))
(indium-debugger-resumed))
@ -405,7 +405,7 @@ If the current connection is closed, display a message."
(callbacks (indium-webkit--callbacks)))
(when callback
(map-put callbacks id callback))
(websocket-send-text (map-elt indium-connection 'ws)
(websocket-send-text (map-elt indium-current-connection 'ws)
(json-encode (cons `(id . ,id) request))))
(message "Socket connection closed")))
@ -419,7 +419,7 @@ If the current connection is closed, display a message."
There is currently no support for the DOM inspector and network
inspectors."
(indium-webkit--enable-runtime)
(unless (map-elt indium-connection 'nodejs)
(unless (map-elt indium-current-connection 'nodejs)
(indium-webkit--enable-page)
(indium-webkit--enable-network)
(indium-webkit--enable-log))


+ 3
- 3
indium-workspace.el View File

@ -138,7 +138,7 @@ If no file is found, return nil."
(defun indium-workspace--make-url-using-file-path (file)
"When using nodejs, the path of FILE should be used directly."
(when (map-elt indium-connection 'nodejs)
(when (map-elt indium-current-connection 'nodejs)
file))
(defun indium-workspace--make-url-using-file-protocol (file)
@ -151,14 +151,14 @@ If the current connection doesn't use the file protocol, return nil."
"Return the url associated with the local FILE.
The url is built using `indium-workspace-root'."
(if-let ((root (indium-workspace-root)))
(let* ((url (indium-workspace--url-basepath (map-elt indium-connection 'url)))
(let* ((url (indium-workspace--url-basepath (map-elt indium-current-connection 'url)))
(path (file-relative-name file root)))
(setf (url-filename url) (indium-workspace--absolute-path path))
(url-recreate-url url))))
(defun indium-workspace--file-protocol-p ()
"Return non-nil if the current connection use the file protocol."
(let ((url (url-generic-parse-url (map-elt indium-connection 'url))))
(let ((url (url-generic-parse-url (map-elt indium-current-connection 'url))))
(string= (url-type url) "file")))
(defun indium-workspace--absolute-path (path)


+ 2
- 2
test/integration/indium-nodejs-integration-test.el View File

@ -41,10 +41,10 @@
(kill-nodejs-process))
(it "should be able to start a node process and connect to it"
(expect indium-connection :to-be nil)
(expect indium-current-connection :to-be nil)
(indium-run-node "node ../fixtures/test.js")
(sleep-for 1)
(expect indium-connection :not :to-be nil))
(expect indium-current-connection :not :to-be nil))
(it "should create a REPL buffer upon connection"
(expect (get-buffer (indium-repl-buffer-name)) :to-be nil)


+ 2
- 2
test/test-helper.el View File

@ -74,9 +74,9 @@ a temporary file, which is removed afterwards."
(ignore-errors (delete-file indium-workspace-file nil)))))
(defmacro with-indium-connection (connection &rest body)
"Evaluate BODY with CONNECTION as the indium-connection."
"Evaluate BODY with CONNECTION as the indium-current-connection."
(declare (indent 1))
`(let ((indium-connection ,connection))
`(let ((indium-current-connection ,connection))
,@body))
(defmacro with-fake-indium-connection (&rest body)


+ 1
- 1
test/unit/indium-webkit-test.el View File

@ -42,7 +42,7 @@
(expect (indium-backend-active-connection-p 'webkit) :to-be-truthy)))
(it "should be inactive if the websocket is closed"
(let ((indium-connection '((backend . webkit))))
(let ((indium-current-connection '((backend . webkit))))
(expect (indium-backend-active-connection-p 'webkit) :to-be nil)))
(it "should close the socket when closing the connection"


Loading…
Cancel
Save