Skip to content

Commit 374fd05

Browse files
tinloafLukas Barth
and
Lukas Barth
authored
Extract environment variables from launch.json (#739)
The launch.json format and the dap-mode format for specifying environment variables is not the same, we need to do some conversion. First, launch.json uses the key 'environment', dap-mode uses 'environment-variables'. Second, launch.json uses a format like {'name': 'foo', 'value': 'bar'} to specify a single variable, while dap-mode uses a ('foo' . 'bar') cons cell. Co-authored-by: Lukas Barth <Lukas Barth [email protected]>
1 parent 24892f9 commit 374fd05

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

dap-launch.el

+24-1
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,34 @@ Yields nil if it cannot be found or there is no project."
8383
Extract the name from the :name property."
8484
(push (dap-launch-configuration-get-name conf) conf))
8585

86+
(defun dap--launch-extract-environment (conf)
87+
"Transform environment config into dap-mode format.
88+
This handles a single configuration plist."
89+
(if (not (plist-get conf :environment))
90+
;; No environment specified, just return the old configuration
91+
conf
92+
;; Standard format for the "environment" key is
93+
;; {"name": "foo", "value": "bar"},
94+
;; which results in a (:name "foo" :value "bar) plist.
95+
;; We need to transform this into a ("foo" . "bar") cons cell.
96+
(let ((environ-spec (mapcar
97+
(lambda (env-plist)
98+
(cons (plist-get env-plist :name)
99+
(plist-get env-plist :value)))
100+
(plist-get conf :environment))))
101+
(plist-put conf :environment-variables environ-spec))))
102+
103+
(defun dap--launch-extract-environments (conflist)
104+
"Transform environment config into dap-mode format.
105+
This is intended to be run on a list of configurations."
106+
(mapcar #'dap--launch-extract-environment conflist))
107+
86108
(defun dap-launch-parse-launch-json (json)
87109
"Return a list of all launch configurations in JSON.
88110
JSON must have been acquired with `dap-launch--get-launch-json'."
89111
(mapcar #'dap-launch-configuration-prepend-name
90-
(or (plist-get json :configurations) (list json))))
112+
(dap--launch-extract-environments
113+
(or (plist-get json :configurations) (list json)))))
91114

92115
(defun dap-launch-find-parse-launch-json ()
93116
"Return a list of all launch configurations for the current project.

0 commit comments

Comments
 (0)