devtools module has been splitted into submodules

This commit is contained in:
Sameer Rahmani 2019-08-25 22:10:23 +01:00
parent 8c25a66513
commit 63afbd12df
9 changed files with 154 additions and 39 deletions

View File

@ -12,6 +12,7 @@
(depends-on 'dockerfile-mode)
(depends-on 'quickrun)
(depends-on 'dash)
(depends-on 'websocket)
(with-ability parinfer
(depends-on 'parinfer))

View File

@ -80,7 +80,6 @@
(with-ability tabbar
(depends-on 'tabbar))
(if (eq system-type 'darwin)
(depends-on 'exec-path-from-shell))

27
lib/fg42/ability.el Normal file
View File

@ -0,0 +1,27 @@
;;; ability --- ability library of FG42
;;; Commentary:
;;;
;;; Code:
(require 'cl-lib)
(defvar fg42--abilities '()
"Internal data structure to store abilities.")
(cl-defstruct fg42-ability
"Each FG42 ability should implement a copy of this structure."
name
docs
depends-on
(start! nil)
(stop! nil))
(defun register-ability (ability-name)
"Register the given ABILITY-NAME as an activity."
(add-to-list
fg42--abilities
'(ability-name . (make-fg42-ability :name ability-name))))
(defun start-ability (ability-name))
(provide 'fg42/ability)
;;; ability ends here

View File

@ -85,6 +85,7 @@
(defvar fg42/devtools-console-input)
(defun fg42/devtools-append-to-console-buffer)
(define-derived-mode fg42/devtools-console-mode comint-mode "fg42/devtools-console"
"Provide a REPL into the visiting browser."
:group 'fg42/devtools
@ -106,12 +107,29 @@
(comint-output-filter (fg42/devtools-console-process) fg42/devtools-console-prompt)
(set-process-filter (fg42/devtools-console-process) 'comint-output-filter)))
(defun fg42/devtools-append-to-console-buffer (log-entry)
(let* ((message (plist-get data :message))
(url (plist-get message :url))
(column (plist-get message :column))
(line (plist-get message :line))
(type (plist-get message :type))
(level (plist-get message :level))
(text (plist-get message :text)))
(->buffer
fg42/devtools-console-buffer-name
(format "[%s:%s:%s]<%s>: %s"
(apply-face 'error url)
line
column
level
message))))
(defun fg42/devtools-console-append (data)
(let ((buffer (get-buffer "*fg42/devtools-console*")))
(when buffer
(with-current-buffer buffer
(comint-output-filter (fg42/devtools-console-process) (concat data "\n"))))))
;; (defun fg42/devtools-console-append (data)
;; (let ((buffer (get-buffer-create fg42/devtools-console-buffer-name)))
;; (when buffer
;; (with-current-buffer buffer
;; (comint-output-filter (fg42/devtools-console-process) (concat data "\n"))))))
(defun fg42/devtools-console-process ()

View File

@ -33,27 +33,9 @@
(require 'dash)
(require 'websocket)
(require 'fg42/utils/json)
(require 'fg42/utils)
;;; Customs & Vars ------------------------------------------------------------
(defcustom fg42/devtools-remote-host "127.0.0.1"
"Default host for connection to WebKit remote debugging API."
:group 'fg42/devtools)
(defcustom fg42/devtools-remote-port 9222
"Default port for connection to WebKit remote debugging API."
:group 'fg42/devtools)
(defvar fg42/devtools-socket nil
"Websocket connection to WebKit remote debugging API.")
(defvar fg42/devtools-rpc-id 0)
(defvar fg42/devtools-rpc-callbacks nil)
(defvar fg42/devtools-rpc-scripts nil
"List of JavaScript files available for live editing.")
(require 'fg42/devtools/vars)
;;; Functions -----------------------------------------------------------------
(defun fg42/devtools-next-rpc-id ()
@ -66,6 +48,7 @@
(let ((hook (intern (number-to-string id) fg42/devtools-rpc-callbacks)))
(add-hook hook fn t)))
(defun fg42/devtools-dispatch-callback (id data)
"Execute the callback registered by the given ID with the given DATA."
(let ((hook (intern (number-to-string id) fg42/devtools-rpc-callbacks)))
@ -91,9 +74,12 @@
(when (and (eq extension? :json-false) (not (string-equal "" url)))
(add-to-list 'fg42/devtools-rpc-scripts (list :id id :url url)))))
(defun fg42/devtools->inspect-buffer (data)
(inspect-data-append (list "ERRRR" data)))
(defun fg42/devtools-on-script-failed-to-parse (data)
(fg42/devtools-console-append (format "%s" data)))
;; (fg42/devtools-console-append (format "%s" data))
(fg42/devtools->inspect-buffer data))
(defun fg42/devtools-on-message-added (data)
@ -105,11 +91,16 @@
(level (plist-get message :level))
(text (plist-get message :text)))
;; TODO: add colors based on level
(fg42/devtools-console-append
(propertize
(format "%s: %s\t%s (line: %s column: %s)"
level text url line column)
'font-lock-face (intern (format "fg42/devtools-log-%s" level))))))
;;(fg42/devtools-console-append
(fg42/devtools->inspect-buffer data)))
;; (fg42/devtools->inspect-buffer
;; (propertize
;; (format "%s: %s\t%s (line: %s column: %s)"
;; level text url line column)
;; 'font-lock-face (intern (format "fg42/devtools-log-%s" level))))))
(defun fg42/devtools-log-added (data)
(fg42/devtools-append-to-console-buffer data))
(defun fg42/devtools-on-message (socket data)
@ -122,12 +113,13 @@
("Debugger.scriptParsed" (fg42/devtools-on-script-parsed params))
;; we are getting an error in Console.messageAdded
;; ("Debugger.scriptFailedToParse" (fg42/devtools-on-script-failed-to-parse params))
("Console.messageAdded" (fg42/devtools-on-message-added params))
("Log.entryAdded" (fg42/devtools-log-added params))
;; ("Console.messageAdded" (fg42/devtools-on-message-added params))
;; ;; TODO: do something usefull here, possibly great for REPL
("Console.messageRepeatCountUpdated")
;; nil -> These are return messages from RPC calls, not notification
(_ (if method
(inspect-data-append data)
(message "FG42: Got a method - %s" method)
(fg42/devtools-dispatch-callback (plist-get data :id)
(plist-get data :result)))))))
@ -143,12 +135,16 @@
:method method
:params params)))))
(defun fg42/devtools-on-error (socket where error)
(message "FG42: Got and error in %s" where)
(message error))
(defun fg42/devtools-open-socket (url)
"Connect to the given URL and return a socket."
(websocket-open url
:on-open #'fg42/devtools-on-open
:on-message #'fg42/devtools-on-message
:on-error #'fg42/devtools-on-error
:on-close #'fg42/devtools-on-close))
@ -203,8 +199,10 @@
(message (format "FG42: Connecting to %s" socket-url))
(setq fg42/devtools-socket (fg42/devtools-open-socket socket-url))
(message "Sending initial RPC calls...")
(fg42/devtools-call-rpc "Console.enable")
;; (fg42/devtools-call-rpc "Console.enable")
(fg42/devtools-call-rpc "Log.enable")
(fg42/devtools-call-rpc "Debugger.enable")
(fg42/devtools-call-rpc "Runtime.enable")
(fg42/devtools-call-rpc "Network.setCacheDisabled" '(:cacheDisabled t))))
@ -309,7 +307,7 @@
(fg42/devtools-connect))
;; (fg42/devtools-debug-restart)
;; (fg42/devtools-disconnect)
(provide 'fg42/devtools)
;;; devtools.el ends here
(provide 'fg42/devtools/core)
;;; core.el ends here

58
lib/fg42/devtools/vars.el Normal file
View File

@ -0,0 +1,58 @@
;;; fg42-devtools --- Webkit devtool driver for FG42
;;
;; Copyright (c) 2019 Sameer Rahmani <lxsameer@gnu.org>
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://gitlab.com/FG42/FG42
;; Keywords: webkit
;; Version: 0.1.0
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Acknoledgement:
;; This library is heavily inspired by Kite mini library. Kudos Tung Dao
;; for his great work.
;;
;;; Commentary:
;;; Code:
;;; Customs & Vars ------------------------------------------------------------
(defcustom fg42/devtools-remote-host "127.0.0.1"
"Default host for connection to WebKit remote debugging API."
:group 'fg42/devtools)
(defcustom fg42/devtools-remote-port 9222
"Default port for connection to WebKit remote debugging API."
:group 'fg42/devtools)
(defvar fg42/devtools-socket nil
"Websocket connection to WebKit remote debugging API.")
(defvar fg42/devtools-rpc-id 0)
(defvar fg42/devtools-rpc-callbacks nil)
(defvar fg42/devtools-rpc-scripts nil
"List of JavaScript files available for live editing.")
(defvar fg42/devtools-console-buffer-name "*1-console*")
(defvar fg42/devtools-network-buffer-name "*2-network*")
(provide 'fg42/devtools/vars)
;;; vars.el ends here

8
lib/fg42/logger.el Normal file
View File

@ -0,0 +1,8 @@
;;; logger --- logger library of FG42
;;; Commentary:
;;;
;;; Code:
(provide 'fg42/logger)
;;; logger ends here

View File

@ -23,7 +23,8 @@ with is the buffer."
(let ((buf (get-buffer-create buffer-name)))
(with-current-buffer buf
(insert data)
(funcall fn buf))))
(when fn
(funcall fn buf)))))
(defun inspect-as-json-and-switch (data)
@ -60,5 +61,10 @@ with is the buffer."
";; END.\n")))
(defun apply-face (face-symbol text)
"Apply the given FACE-SYMBOL to the given TEXT."
(put-text-property 0 (length text) 'face face-symbol text))
(provide 'fg42/utils)
;;; utils.el ends here