Skip to content

Commit 4db261e

Browse files
authored
dap-features->windows: add REPL window (emacs-lsp#285)
1 parent e0ce394 commit 4db261e

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

dap-mode.el

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,20 @@ The hook will be called with the session file and the new set of breakpoint loca
143143
(defcustom dap-auto-configure-features '(sessions locals breakpoints expressions controls tooltip)
144144
"Windows to auto show on debugging when in dap-ui-auto-configure-mode."
145145
:group 'dap-mode
146-
:type '(set (const :tag "Show sessions popup window when debugging and enable `dap-ui-sessions-mode`" sessions)
146+
:type '(set (const :tag "Show sessions popup window when debugging" sessions)
147147
(const :tag "Show locals popup window when debugging" locals)
148-
(const :tag "Show breakpoints popup window when debugging and enable `dap-ui-breakpoints-mode`" breakpoints)
148+
(const :tag "Show breakpoints popup window when debugging" breakpoints)
149149
(const :tag "Show expressions popup window when debugging" expressions)
150+
(const :tag "Show REPL popup window when debugging" repl)
150151
(const :tag "Enable `dap-ui-controls-mode` with controls to manage the debug session when debugging" controls)
151152
(const :tag "Enable `dap-tooltip-mode` that enables mouse hover support when debugging" tooltip)))
152153

153154
(defconst dap-features->windows
154155
'((sessions . (dap-ui-sessions . dap-ui--sessions-buffer))
155156
(locals . (dap-ui-locals . dap-ui--locals-buffer))
156157
(breakpoints . (dap-ui-breakpoints . dap-ui--breakpoints-buffer))
157-
(expressions . (dap-ui-expressions . dap-ui--expressions-buffer))))
158+
(expressions . (dap-ui-expressions . dap-ui--expressions-buffer))
159+
(repl . (dap-ui-repl . dap-ui--repl-buffer))))
158160

159161
(defconst dap-features->modes
160162
'((controls . (dap-ui-controls-mode . posframe))
@@ -163,6 +165,12 @@ The hook will be called with the session file and the new set of breakpoint loca
163165
(defvar dap--debug-configuration nil
164166
"List of the previous configuration that have been executed.")
165167

168+
(defvar dap-connect-retry-count 1000
169+
"Retry count for dap connect.")
170+
171+
(defvar dap-connect-retry-interval 0.02
172+
"Retry interval for dap connect.")
173+
166174
(defun dash-expand:&dap-session (key source)
167175
`(,(intern-soft (format "dap--debug-session-%s" (eval key) )) ,source))
168176

@@ -1578,12 +1586,6 @@ If the current session it will be terminated."
15781586
(dap--set-breakpoints-in-file buffer-file-name))
15791587
(add-hook 'kill-buffer-hook 'dap--buffer-killed nil t)))
15801588

1581-
(defvar dap-connect-retry-count 1000
1582-
"Retry count for dap connect.")
1583-
1584-
(defvar dap-connect-retry-interval 0.02
1585-
"Retry interval for dap connect.")
1586-
15871589
(defun dap-mode-mouse-set-clear-breakpoint (event)
15881590
"Set or remove a breakpoint at the position represented by an
15891591
`event' mouse click. If `dap-mode' is not enabled, then only the

dap-ui-repl.el

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
;;; Commentary:
66

7-
;; This code is heavily based on `skewer-repl'. Run `dap-ui-repl' to switch to
7+
;; This code is heavily based on `skewer-repl'. Run `dap-ui-repl' to switch to
88
;; the REPL buffer and evaluate code.
99

1010
;;; Code:
@@ -28,6 +28,8 @@ Hack notice: this allows log messages to appear before anything is
2828
evaluated because it provides insertable space at the top of the
2929
buffer.")
3030

31+
(defconst dap-ui--repl-buffer "*dap-ui-repl*")
32+
3133
(defun dap-ui-repl-process ()
3234
"Return the process for the dap-ui REPL."
3335
(get-buffer-process (current-buffer)))
@@ -65,7 +67,7 @@ INPUT is the current input."
6567
(list :expression input
6668
:frameId active-frame-id))
6769
(-lambda ((&hash "success" "message" "body"))
68-
(-when-let (buffer (get-buffer "*dap-ui-repl*"))
70+
(-when-let (buffer (get-buffer dap-ui--repl-buffer))
6971
(with-current-buffer buffer
7072
(comint-output-filter (dap-ui-repl-process)
7173
(concat (if success (gethash "result" body) message)
@@ -79,13 +81,15 @@ INPUT is the current input."
7981
"Start a JavaScript REPL to be evaluated in the visiting browser."
8082
(interactive)
8183
(let ((workspaces (lsp-workspaces)))
82-
(unless (get-buffer "*dap-ui-repl*")
83-
(with-current-buffer (get-buffer-create "*dap-ui-repl*")
84+
(unless (get-buffer dap-ui--repl-buffer)
85+
(with-current-buffer (get-buffer-create dap-ui--repl-buffer)
8486
(dap-ui-repl-mode)
8587
(when (functionp 'company-mode)
8688
(company-mode 1))
8789
(setq-local lsp--buffer-workspaces workspaces))))
88-
(pop-to-buffer (get-buffer "*dap-ui-repl*")))
90+
(if (called-interactively-p 'any)
91+
(pop-to-buffer dap-ui--repl-buffer)
92+
(display-buffer dap-ui--repl-buffer)))
8993

9094
(defun dap-ui-repl--calculate-candidates ()
9195
"Calculate candidates.

dap-ui.el

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
(require 'compile)
3535
(require 'gdb-mi)
3636
(require 'lsp-treemacs)
37+
(require 'dap-ui-repl)
3738

3839
(defcustom dap-ui-stack-frames-loaded nil
3940
"Stack frames loaded."
@@ -854,7 +855,7 @@ DEBUG-SESSION is the debug session triggering the event."
854855
(region-end)))
855856
(t (symbol-at-point))))))
856857
(when (-contains? dap-ui-expressions expression)
857-
(user-error "\"%s\" is already watched." expression))
858+
(user-error "\"%s\" is already watched" expression))
858859
(add-to-list 'dap-ui-expressions expression)
859860
(dap-ui-expressions)
860861
(dap-ui-expressions-refresh))
@@ -866,7 +867,7 @@ DEBUG-SESSION is the debug session triggering the event."
866867
nil
867868
t)))
868869
(unless (-contains? dap-ui-expressions expression)
869-
(user-error "\"%s\" is not present." expression))
870+
(user-error "\"%s\" is not present" expression))
870871
(setq dap-ui-expressions (remove expression dap-ui-expressions))
871872
(dap-ui-expressions-refresh))
872873

@@ -1123,8 +1124,10 @@ DEBUG-SESSION is the debug session triggering the event."
11231124
(defun dap-ui--hide-many-windows (_session)
11241125
"Hide all debug windows when sessions are dead."
11251126
(seq-doseq (feature-start-stop dap-auto-configure-features)
1126-
(-when-let* ((feature-start-stop (alist-get feature-start-stop dap-features->windows))
1127-
(buffer-name (symbol-value (cdr feature-start-stop))))
1127+
(when-let* ((feature-start-stop (alist-get feature-start-stop dap-features->windows))
1128+
(buffer-name (symbol-value (cdr feature-start-stop))))
1129+
(when-let (window (get-buffer-window buffer-name))
1130+
(delete-window window))
11281131
(and (get-buffer buffer-name)
11291132
(kill-buffer buffer-name)))))
11301133

0 commit comments

Comments
 (0)