From 19344496bc5a9ac397bfd6cceac3eaf5f60ecad8 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 10 Mar 2025 16:00:11 -0700 Subject: [PATCH] fix: fixes error when a utility frame is the current frame On Mac OS X, small frames that don't seem to have any windows may be selected when the process filter is processed. By walking up the parent-frame list, we can get to the frame that the user is actually able to use, and thus the call to (get-mru-window) does not return nil and the whole process filter aborts. Should fix bug #828 --- dap-mode.el | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dap-mode.el b/dap-mode.el index 4c4a09c..723813b 100644 --- a/dap-mode.el +++ b/dap-mode.el @@ -784,7 +784,7 @@ will be reversed." (-when-let* ((source (gethash "source" stack-frame)) (sourceReference (gethash "sourceReference" source)) (sourceReferenceKey (format "%s-%s" name sourceReference))) - (select-window (get-mru-window (selected-frame) nil)) + (select-window (get-mru-window (dap--selected-frame) nil)) (if-let* ((existing-buffer (get-buffer sourceReferenceKey))) (switch-to-buffer existing-buffer) (dap--send-message @@ -810,6 +810,15 @@ will be reversed." path))) (--> debug-session (dap--debug-session-remote-to-local-path-fn it) (funcall it remote-path))))) +(defun dap--selected-frame () + "Select the 'main' frame when we have a utility/subframe selected" + (cl-labels ((helper (f) + (let ((parent-frame (frame-parameter f 'parent-frame))) + (if parent-frame + (helper parent-frame) + f)))) + (helper (selected-frame)))) + (defun dap--go-to-stack-frame (debug-session stack-frame) "Make STACK-FRAME the active STACK-FRAME of DEBUG-SESSION." (when stack-frame @@ -821,7 +830,7 @@ will be reversed." ;; stack trace. (if (and path (file-exists-p path)) (progn - (select-window (get-mru-window (selected-frame) nil)) + (select-window (get-mru-window (dap--selected-frame) nil)) (find-file path) (goto-char (point-min)) (forward-line (1- line))