emacs-lsp / dap-mode

Emacs :heart: Debug Adapter Protocol
https://emacs-lsp.github.io/dap-mode
GNU General Public License v3.0
1.3k stars 181 forks source link

dap-mode not using direnv #776

Open LemonBreezes opened 8 months ago

LemonBreezes commented 8 months ago

dap-mode is not launching my program with the environment variables I set in my .envrc and have set buffer-local to my code files using direnv. Related issues: https://github.com/emacs-lsp/lsp-mode/issues/2583, https://github.com/purcell/envrc/issues/71.

LemonBreezes commented 8 months ago

I just came up with a hacky advice to work around this:

(defun cae-dap-debug-pass-envrc-a (args)
  (when (length= (plist-get (car args) :environment) 0)
    (plist-put (car args) :environment
               (apply #'vector
                      (mapcar (lambda (s)
                                (let ((m (string-match "=" s)))
                                  (if m
                                      (list :name
                                            (substring-no-properties s 0 m)
                                            :value
                                            (substring-no-properties s (1+ m)
                                                                     (length s)))
                                    (list :name s
                                          :value ""))))
                              process-environment))))
  args)
(advice-add #'dap-start-debugging-noexpand :filter-args
            #'cae-dap-debug-pass-envrc-a)

Maybe we can add something like this to the package. An option to propagate the program being debugged.