Fix +debug/start
for dap-based debuggers.
Reworks the internals of how the debugger module stores the last-used configuration: - car of the configuration indicates whether it is a realgud or a dap-based configuration. - For dap-based debuggers, the entire dap configuration is stored, with code copied from `dab-debug`. - When inside a project, don't store the configuration as a buffer-local variable, but instead as a project-local variable using `projectile-variable`. Fixes #2367.
This commit is contained in:
parent
88e18fc7c1
commit
6de1e56d4f
2 changed files with 74 additions and 27 deletions
|
@ -1,28 +1,70 @@
|
||||||
;;; tools/debugger/autoload/debugger.el -*- lexical-binding: t; -*-
|
;;; tools/debugger/autoload/debugger.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
(defvar +debugger--last nil)
|
(defvar +debugger-last-configuration nil
|
||||||
|
"Configuration of the last debugging session of buffer.")
|
||||||
|
(make-variable-buffer-local '+debugger-last-configuration)
|
||||||
|
|
||||||
|
(defun +debugger-get-configuration ()
|
||||||
|
"Get last debugging configuration.
|
||||||
|
|
||||||
|
If in a project, returns the configuration of the last debugging session in the
|
||||||
|
project, if any. Else, returns the last debugging configuration of the current
|
||||||
|
buffer, if any."
|
||||||
|
(if (projectile-project-p)
|
||||||
|
(projectile-variable-get '+debugger-last-configuration)
|
||||||
|
+debugger-last-configuration))
|
||||||
|
|
||||||
|
(defun +debugger-set-configuration (configuration)
|
||||||
|
"Set the debugging configuration.
|
||||||
|
|
||||||
|
If in a project, sets the project's debugging session configuration. Else, sets
|
||||||
|
the debugging configuration of the current buffer."
|
||||||
|
(if (projectile-project-p)
|
||||||
|
(projectile-variable-put '+debugger-last-configuration configuration)
|
||||||
|
(setq-local +debugger-last-configuration configuration)))
|
||||||
|
|
||||||
(defun +debugger-list-for-dap ()
|
(defun +debugger-list-for-dap ()
|
||||||
(when (and (bound-and-true-p lsp-mode)
|
(when (and (bound-and-true-p lsp-mode)
|
||||||
(bound-and-true-p lsp--buffer-deferred)
|
(bound-and-true-p lsp--buffer-deferred)
|
||||||
(require 'dap-mode nil t)
|
(require 'dap-mode nil t)
|
||||||
dap-mode)
|
dap-mode)
|
||||||
(mapcar #'car dap-debug-template-configurations)))
|
(--map (cons 'dap it)
|
||||||
|
(-mapcat #'funcall dap-launch-configuration-providers))))
|
||||||
|
|
||||||
(defun +debugger-list-for-realgud ()
|
(defun +debugger-list-for-realgud ()
|
||||||
(cl-loop for (sym . plist) in +debugger--realgud-alist
|
(--map (cons 'realgud (list (symbol-name it)))
|
||||||
for sym-name = (symbol-name sym)
|
(cl-loop for (sym . plist) in +debugger--realgud-alist
|
||||||
for modes = (plist-get plist :modes)
|
for sym-name = (symbol-name sym)
|
||||||
if (or (null modes) (apply #'derived-mode-p modes))
|
for modes = (plist-get plist :modes)
|
||||||
collect sym))
|
if (or (null modes) (apply #'derived-mode-p modes))
|
||||||
|
collect sym)))
|
||||||
|
|
||||||
|
;; Based on dap--completing-read and dap-debug
|
||||||
|
(defun +debugger-completing-read ()
|
||||||
|
"Completing read for debug configuration.
|
||||||
|
|
||||||
(defun +debugger-list-available ()
|
Presents both dap and realgud configurations, and returns a list of the form
|
||||||
"TODO"
|
('dap ...) or ('realgud ...) containing the corresponding debug configuration
|
||||||
(append (+debugger-list-for-dap)
|
infromation."
|
||||||
(+debugger-list-for-realgud)
|
(let* ((configurations (append
|
||||||
nil))
|
(+debugger-list-for-dap)
|
||||||
|
(+debugger-list-for-realgud)))
|
||||||
|
(result (--map (cons (cadr it) it) configurations))
|
||||||
|
(completion (completing-read "Start debugger: " (-map 'car result) nil t ))
|
||||||
|
(configuration (cdr (assoc completion result))))
|
||||||
|
(if (eq (car configuration) 'dap)
|
||||||
|
(let* ((debug-args (-> (cdr configuration)
|
||||||
|
cl-rest
|
||||||
|
copy-tree
|
||||||
|
dap-variables-expand-in-launch-configuration))
|
||||||
|
(launch-args (or (-some-> (plist-get debug-args :type)
|
||||||
|
(gethash dap--debug-providers)
|
||||||
|
(funcall debug-args))
|
||||||
|
(user-error "Have you loaded the `%s' specific dap package?"
|
||||||
|
(or (plist-get debug-args :type)
|
||||||
|
(user-error "%s does not specify :type" debug-args))))))
|
||||||
|
(cons 'dap launch-args))
|
||||||
|
(cons 'realgud (intern (cadr configuration))))))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;;; Interactive commands
|
;;; Interactive commands
|
||||||
|
@ -31,9 +73,20 @@
|
||||||
(defun +debugger/start-last ()
|
(defun +debugger/start-last ()
|
||||||
"Relaunch the last debugger session."
|
"Relaunch the last debugger session."
|
||||||
(interactive)
|
(interactive)
|
||||||
(unless +debugger--last
|
(let ((configuration (+debugger-get-configuration)))
|
||||||
(user-error "No last debugger to invoke"))
|
(unless configuration
|
||||||
(call-interactively +debugger--last))
|
(user-error "No last debugger%s to invoke"
|
||||||
|
(if (projectile-project-p)
|
||||||
|
" of this project"
|
||||||
|
"")))
|
||||||
|
(let ((launch-args (cdr configuration)))
|
||||||
|
(if (eq (car configuration) 'dap)
|
||||||
|
;; start dap configuration
|
||||||
|
(if (functionp launch-args)
|
||||||
|
(funcall launch-args #'dap-start-debugging-noexpand)
|
||||||
|
(dap-start-debugging-noexpand launch-args))
|
||||||
|
;; else start realgud configuration:
|
||||||
|
(call-interactively launch-args)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +debugger/start (arg)
|
(defun +debugger/start (arg)
|
||||||
|
@ -42,17 +95,9 @@
|
||||||
Launches the last used debugger, if one exists. Otherwise, you will be prompted
|
Launches the last used debugger, if one exists. Otherwise, you will be prompted
|
||||||
for what debugger to use. If the prefix ARG is set, prompt anyway."
|
for what debugger to use. If the prefix ARG is set, prompt anyway."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(if (or arg (null +debugger--last))
|
(if (or arg (null (+debugger-get-configuration)))
|
||||||
(let ((debugger (intern-soft (completing-read "Start debugger: " (+debugger-list-available)))))
|
(+debugger-set-configuration (+debugger-completing-read)))
|
||||||
(unless debugger
|
(+debugger/start-last))
|
||||||
(user-error "No debugging session to quit"))
|
|
||||||
(unless (fboundp debugger)
|
|
||||||
(user-error "Couldn't find debugger backend %S" debugger))
|
|
||||||
(setq-local +debugger--last debugger)
|
|
||||||
(if (assoc debugger dap-debug-template-configurations)
|
|
||||||
(dap-debug debugger)
|
|
||||||
(call-interactively debugger)))
|
|
||||||
(+debugger/start-last)))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +debugger/quit ()
|
(defun +debugger/quit ()
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
(when (featurep! :lang javascript)
|
(when (featurep! :lang javascript)
|
||||||
(package! realgud-trepan-ni :pin "6e38cf838c7b47b5f1353d00901b939ffa36d707")))
|
(package! realgud-trepan-ni :pin "6e38cf838c7b47b5f1353d00901b939ffa36d707")))
|
||||||
|
|
||||||
|
(package! projectile-variable :pin "8d348ac70bdd6dc320c13a12941b32b38140e264")
|
||||||
|
|
||||||
(when (featurep! +lsp)
|
(when (featurep! +lsp)
|
||||||
(package! dap-mode :pin "aa15b9c49b7e09bb23f9a4ff7855122f0eb19976")
|
(package! dap-mode :pin "aa15b9c49b7e09bb23f9a4ff7855122f0eb19976")
|
||||||
(package! posframe :pin "3454a4cb9d218c38f9c5b88798dfb2f7f85ad936"))
|
(package! posframe :pin "3454a4cb9d218c38f9c5b88798dfb2f7f85ad936"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue