Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract environment variables from launch.json #739

Merged
merged 1 commit into from
May 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading