-
Notifications
You must be signed in to change notification settings - Fork 182
/
dap-chrome.el
84 lines (68 loc) · 3.33 KB
/
dap-chrome.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
;;; dap-chrome.el --- Debug Adapter Protocol mode for Chrome -*- lexical-binding: t; -*-
;; Copyright (C) 2019 Ivan Yonchovski
;; Author: Ivan Yonchovski <yyoncho@gmail.com>
;; Keywords: languages
;; 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 <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Adapter for https://github.com/chromeide/vscode-chrome
;;; Code:
(require 'dap-mode)
(require 'dap-utils)
(defcustom dap-chrome-debug-path (expand-file-name "vscode/msjsdiag.debugger-for-chrome"
dap-utils-extension-path)
"The path to chrome vscode extension."
:group 'dap-chrome
:type 'string)
(defcustom dap-chrome-debug-program `("node"
,(f-join dap-chrome-debug-path "extension/out/src/chromeDebug.js"))
"The path to the chrome debugger."
:group 'dap-chrome
:type '(repeat string))
(dap-utils-vscode-setup-function "dap-chrome" "msjsdiag" "debugger-for-chrome"
dap-chrome-debug-path)
(defun dap-chrome--populate-start-file-args (conf)
"Populate CONF with the required arguments."
(setq conf (-> conf
(plist-put :type "chrome")
(plist-put :dap-server-path dap-chrome-debug-program)
(dap--put-if-absent :cwd (expand-file-name default-directory))))
(dap--plist-delete
(pcase (plist-get conf :mode)
("url" (-> conf
(dap--put-if-absent :url (read-string
"Browse url: "
"http://localhost:4200" t))
(dap--put-if-absent :webRoot (lsp-workspace-root))))
("file" (dap--put-if-absent conf :file
(read-file-name "Select the file to open in the browser:"
nil (buffer-file-name) t)))
(_ conf))
:mode))
(dap-register-debug-provider "chrome" #'dap-chrome--populate-start-file-args)
(dap-register-debug-template "Chrome Browse File"
(list :type "chrome"
:mode "file"
:cwd nil
:request "launch"
:file nil
:reAttach t
:name "Chrome Browse File"))
(dap-register-debug-template "Chrome Browse URL"
(list :type "chrome"
:cwd nil
:mode "url"
:request "launch"
:webRoot nil
:url nil
:name "Chrome Browse URL"))
(provide 'dap-chrome)
;;; dap-chrome.el ends here