@@ -1647,12 +1647,22 @@ before starting the debug process."
16471647 (push (cons session-name launch-args) dap--debug-configuration)
16481648 (run-hook-with-args 'dap-session-created-hook debug-session)))))
16491649
1650+ (defcustom dap-debug-compilation-keep nil
1651+ " Whether `dap-debug' should keep the compile window on success.
1652+ By default, it is hidden."
1653+ :type 'boolean
1654+ :group 'dap-mode )
1655+
16501656;;;### autoload
16511657(defun dap-debug (debug-args )
16521658 " Run debug configuration DEBUG-ARGS.
16531659
16541660If DEBUG-ARGS is not specified the configuration is generated
1655- after selecting configuration template."
1661+ after selecting configuration template.
1662+
1663+ :dap-compilation specifies a shell command to be run using
1664+ `compilation-start' before starting the debug session. It could
1665+ be used to compile the project, spin up docker, ...."
16561666 (interactive (list (-> (dap--completing-read " Select configuration template: "
16571667 (-mapcat #'funcall dap-launch-configuration-providers)
16581668 'cl-first nil t )
@@ -1670,10 +1680,29 @@ after selecting configuration template."
16701680 (funcall debug-args))
16711681 (user-error " Have you loaded the `%s' specific dap package?"
16721682 (or (plist-get debug-args :type )
1673- (user-error " %s does not specify :type" debug-args))))))
1674- (if (functionp launch-args)
1675- (funcall launch-args #'dap-start-debugging-noexpand )
1676- (dap-start-debugging-noexpand launch-args))))
1683+ (user-error " %s does not specify :type" debug-args)))))
1684+ (cb (lambda ()
1685+ (if (functionp launch-args)
1686+ (funcall launch-args #'dap-start-debugging-noexpand )
1687+ (dap-start-debugging-noexpand launch-args)))))
1688+ (-if-let ((&plist :dap-compilation compilation) launch-args)
1689+ (progn
1690+ (cl-remf launch-args :dap-compilation )
1691+ (with-current-buffer (compilation-start compilation t (lambda (&rest _ )
1692+ " *DAP compilation*" ))
1693+ (let (window)
1694+ (add-hook 'compilation-finish-functions
1695+ (lambda (buf status &rest _ )
1696+ (if (string= " finished\n " status)
1697+ (progn
1698+ (when (and (not dap-debug-compilation-keep)
1699+ (window-live-p window)
1700+ (eq buf (window-buffer window)))
1701+ (delete-window window))
1702+ (funcall cb))
1703+ (lsp--error " Compilation step failed" ))))
1704+ (setq window (display-buffer (current-buffer ))))))
1705+ (funcall cb))))
16771706
16781707(defun dap-debug-edit-template (&optional debug-args )
16791708 " Edit registered template DEBUG-ARGS.
@@ -1699,11 +1728,11 @@ normally with `dap-debug'"
16991728 ((fst snd . rst) debug-args))
17001729 (insert (format " %s %s " fst (prin1-to-string snd)))
17011730 (cl-loop for (k v) on rst by #'cddr
1702- do (if (not (equal k :program-to-start ))
1703- (progn
1704- (insert " \n " )
1705- (--dotimes column (insert " " ))
1706- (insert (format " %s %s " k (prin1-to-string v)))))))
1731+ do (if (not (equal k :program-to-start ))
1732+ (progn
1733+ (insert " \n " )
1734+ (--dotimes column (insert " " ))
1735+ (insert (format " %s %s " k (prin1-to-string v)))))))
17071736 (insert " ))" ))
17081737 (pop-to-buffer " *DAP Templates*" )
17091738 (goto-char (point-max )))
0 commit comments