Skip to content

Commit

Permalink
Extract environment variables from launch.json (#739)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
tinloaf and Lukas Barth authored May 10, 2023
1 parent 24892f9 commit 374fd05
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion dap-launch.el
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,34 @@ Yields nil if it cannot be found or there is no project."
Extract the name from the :name property."
(push (dap-launch-configuration-get-name conf) conf))

(defun dap--launch-extract-environment (conf)
"Transform environment config into dap-mode format.
This handles a single configuration plist."
(if (not (plist-get conf :environment))
;; No environment specified, just return the old configuration
conf
;; Standard format for the "environment" key is
;; {"name": "foo", "value": "bar"},
;; which results in a (:name "foo" :value "bar) plist.
;; We need to transform this into a ("foo" . "bar") cons cell.
(let ((environ-spec (mapcar
(lambda (env-plist)
(cons (plist-get env-plist :name)
(plist-get env-plist :value)))
(plist-get conf :environment))))
(plist-put conf :environment-variables environ-spec))))

(defun dap--launch-extract-environments (conflist)
"Transform environment config into dap-mode format.
This is intended to be run on a list of configurations."
(mapcar #'dap--launch-extract-environment conflist))

(defun dap-launch-parse-launch-json (json)
"Return a list of all launch configurations in JSON.
JSON must have been acquired with `dap-launch--get-launch-json'."
(mapcar #'dap-launch-configuration-prepend-name
(or (plist-get json :configurations) (list json))))
(dap--launch-extract-environments
(or (plist-get json :configurations) (list json)))))

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

0 comments on commit 374fd05

Please sign in to comment.