[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dape ccb6060b55 067/123: Add disconnect functionality a
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dape ccb6060b55 067/123: Add disconnect functionality and PID helper for attach requests |
Date: |
Tue, 5 Dec 2023 03:58:01 -0500 (EST) |
branch: externals/dape
commit ccb6060b5555f7145bc6abca86f3325a5d66142a
Author: Daniel Pettersson <daniel@dpettersson.net>
Commit: Daniel Pettersson <daniel@dpettersson.net>
Add disconnect functionality and PID helper for attach requests
---
dape.el | 118 ++++++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 81 insertions(+), 37 deletions(-)
diff --git a/dape.el b/dape.el
index b53dfbadb7..bbf719afc7 100644
--- a/dape.el
+++ b/dape.el
@@ -142,6 +142,7 @@ The hook is run with one argument, the compilation buffer."
("out" . dape-step-out)
("restart" . dape-restart)
("kill" . dape-kill)
+ ("disconnect" . dape-disconnect-quit)
("quit" . dape-quit))
"Dape commands available in REPL buffer."
:type '(alist :key-type string
@@ -371,6 +372,7 @@ If PULSE pulse on after opening file."
(when-let ((marker (dape--object-to-marker plist)))
(let ((window
(display-buffer (marker-buffer marker)
+ ;; TODO Should probably be an custom
'(display-buffer-reuse-window
display-buffer-pop-up-window))))
(unless no-select
@@ -406,6 +408,22 @@ DEFAULT specifies which file to return on empty input."
"Read filename at project root, defaulting to current buffer."
(dape-find-file (buffer-file-name)))
+(defun dape-read-pid ()
+ "Read pid of active processes if possible."
+ (if-let ((pids (list-system-processes)))
+ (let ((collection
+ (mapcar (lambda (pid)
+ (let ((args (alist-get 'args (process-attributes pid))))
+ (cons (concat
+ (format "%d" pid)
+ (when args
+ (format ": %s" args)))
+ pid)))
+ pids)))
+ (alist-get (completing-read "Pid: " collection)
+ collection nil nil 'equal))
+ (read-number "Pid: ")))
+
(defun dape--overlay-region (&optional extended)
"List of beg and end of current line.
If EXTENDED end of line is after newline."
@@ -446,6 +464,26 @@ If EXTENDED end of line is after newline."
(format ":%d"
line))))
+(defun dape--kill-processes ()
+ "Kill all Dape related process."
+ (ignore-errors
+ (and dape--process
+ (delete-process dape--process))
+ (and dape--server-process
+ (delete-process dape--server-process))
+ (and dape--parent-process
+ (delete-process dape--parent-process))))
+
+(defun dape--kill-buffers ()
+ "Kill all Dape related buffers."
+ (thread-last (buffer-list)
+ (seq-filter (lambda (buffer)
+ (string-match-p "\\*dape-.+\\*" (buffer-name
buffer))))
+ (seq-do (lambda (buffer)
+ (when-let ((window (get-buffer-window buffer)))
+ (delete-window window))
+ (kill-buffer buffer)))))
+
;;; Process and parsing
@@ -490,6 +528,12 @@ If NOWARN does not error on no active process."
"Sentinel for dape processes."
(unless (process-live-p process)
(dape--remove-stack-pointers)
+ (dape--variable-remove-overlays)
+ ;; Clean mode-line after 2 seconds
+ (run-with-timer 2 nil (lambda ()
+ (unless (dape--live-process t)
+ (setq dape--process nil)
+ (force-mode-line-update t))))
(dape--debug 'info "\nProcess %S exited with %d"
(process-command process)
(process-exit-status process))))
@@ -534,7 +578,8 @@ If NOWARN does not error on no active process."
(defun dape--process-filter (process string)
"Filter for dape processes."
- (when-let ((input-buffer (process-buffer process))
+ (when-let (((process-live-p process))
+ (input-buffer (process-buffer process))
(buffer (current-buffer)))
(with-current-buffer input-buffer
(goto-char (point-max))
@@ -552,7 +597,8 @@ If NOWARN does not error on no active process."
(dape--debug 'std-server
"%s"
(buffer-substring start
(match-beginning 0)))
- (delete-region start (match-beginning 0)))
+ (when (buffer-live-p input-buffer)
+ (delete-region start (match-beginning 0))))
(json-parse-buffer :object-type 'plist
:null-object nil
:false-object nil))
@@ -571,7 +617,11 @@ If NOWARN does not error on no active process."
(unless parser-error
;; Parser error is probably because of incomplete json
;; We just need more bytes, if that's not the case we are screwed
- (delete-region (point-min) (point)))))))
+
+ ;; This seams like we are living a bit dangerous. If input buffer
+ ;; is killed we are going to erase some random buffer
+ (when (buffer-live-p input-buffer)
+ (delete-region (point-min) (point))))))))
;;; Outgoing requests
@@ -1024,10 +1074,10 @@ Starts a new process as per request of the debug
adapter."
(cl-defmethod dape-handle-event (_process (_event (eql continued)) body)
"Handle continued events."
+ (dape--update-state "running")
(dape--remove-stack-pointers)
(unless dape--thread-id
- (setq dape--thread-id (plist-get body :threadId)))
- (dape--update-state "running"))
+ (setq dape--thread-id (plist-get body :threadId))))
(cl-defmethod dape-handle-event (_process (_event (eql output)) body)
"Handle output events."
@@ -1052,8 +1102,8 @@ Starts a new process as per request of the debug adapter."
(cl-defmethod dape-handle-event (_process (_event (eql terminated)) _body)
"Handle terminated events."
(dape--update-state "terminated")
- (dape--repl-insert-text "* Program terminated *\n" 'italic)
- (dape--remove-stack-pointers))
+ (dape--remove-stack-pointers)
+ (dape--repl-insert-text "* Program terminated *\n" 'italic))
;;; Startup/Setup
@@ -1196,24 +1246,7 @@ Starts a new process as per request of the debug
adapter."
(defun dape-kill ()
"Kill debug session."
(interactive)
- (let* (done
- (kill-processes
- (lambda (&rest _)
- (ignore-errors
- (and dape--process
- (delete-process dape--process))
- (and dape--server-process
- (delete-process dape--server-process))
- (and dape--parent-process
- (delete-process dape--parent-process)))
- (dape--remove-stack-pointers)
- (dape--variable-remove-overlays)
- ;; Clean mode-line after 2 seconds
- (run-with-timer 2 nil (lambda ()
- (unless (dape--live-process t)
- (setq dape--process nil)
- (force-mode-line-update t))))
- (setq done t))))
+ (let (done)
(cond
((and (dape--live-process t)
(plist-get dape--capabilities
@@ -1221,14 +1254,16 @@ Starts a new process as per request of the debug
adapter."
(dape-request dape--process
"terminate"
nil
- kill-processes)
+ (dape--callback
+ (dape--kill-processes)
+ (setq done t)))
;; Busy wait for response at least 2 seconds
(cl-loop with max-iterations = 20
for i from 1 to max-iterations
until done
do (accept-process-output nil 0.1)
finally (unless done
- (funcall kill-processes)
+ (dape--kill-processes)
(dape--debug 'error
"Terminate request timed out"))))
((and (dape--live-process t)
@@ -1238,30 +1273,38 @@ Starts a new process as per request of the debug
adapter."
"disconnect"
(list
:terminateDebuggee t)
- kill-processes)
+ (dape--callback
+ (dape--kill-processes)
+ (setq done t)))
;; Busy wait for response at least 2 seconds
(cl-loop with max-iterations = 20
for i from 1 to max-iterations
until done
do (accept-process-output nil 0.1)
finally (unless done
- (funcall kill-processes)
+ (dape--kill-processes)
(dape--debug 'error
"Disconnect request timed out"))))
(t
- (funcall kill-processes)))))
+ (dape--kill-processes)))))
+
+(defun dape-disconnect-quit ()
+ "Kill adapter but try to keep debuggee live.
+This will leave a decoupled debuggee process with no debugge
+ connection."
+ (interactive)
+ (dape-request (dape--live-process)
+ "disconnect"
+ (list :terminateDebuggee nil)
+ (dape--callback
+ (dape--kill-processes)
+ (dape--kill-buffers))))
(defun dape-quit ()
"Kill debug session and kill related dape buffers."
(interactive)
(dape-kill)
- (thread-last (buffer-list)
- (seq-filter (lambda (buffer)
- (string-match-p "\\*dape-.+\\*" (buffer-name
buffer))))
- (seq-do (lambda (buffer)
- (when-let ((window (get-buffer-window buffer)))
- (delete-window window))
- (kill-buffer buffer)))))
+ (dape--kill-buffers))
(defun dape-toggle-breakpoint ()
"Add or remove breakpoint at current line.
@@ -2685,6 +2728,7 @@ See `eldoc-documentation-functions', for more infomation."
(define-key map "t" #'dape-select-thread)
(define-key map "S" #'dape-select-stack)
(define-key map "w" #'dape-watch-dwim)
+ (define-key map "D" #'dape-disconnect-quit)
(define-key map "q" #'dape-quit)
map))
- [elpa] externals/dape ed37a0cd5b 025/123: Add exception breakpoints, (continued)
- [elpa] externals/dape ed37a0cd5b 025/123: Add exception breakpoints, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 8418a68442 026/123: Fix repl faces, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 815a880f48 027/123: Rename dape input vars, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 4eb75e39b2 031/123: Small readme fixup, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 04aabf1862 041/123: Update screenshots, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 95d52ea585 044/123: Fix parsing of codelldb adapter output on windows #1, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 3d800b349e 045/123: Add godot example config, ELPA Syncer, 2023/12/05
- [elpa] externals/dape b42b7def86 046/123: Fix timers when repl buffer is not available, ELPA Syncer, 2023/12/05
- [elpa] externals/dape efcfc93003 047/123: Fix duplicate variable overlays, ELPA Syncer, 2023/12/05
- [elpa] externals/dape cacddbb8e7 057/123: Improve error printout and do a better job of validating config, ELPA Syncer, 2023/12/05
- [elpa] externals/dape ccb6060b55 067/123: Add disconnect functionality and PID helper for attach requests,
ELPA Syncer <=
- [elpa] externals/dape 6da668abc4 009/123: Fix themes link in readme, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 6c501bfbc9 004/123: Fix watch dwim use symbol at point, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 96b1815ed3 001/123: Initial commit, ELPA Syncer, 2023/12/05
- [elpa] externals/dape a21992c208 002/123: Add screenshot, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 6907fade6a 003/123: Fixup readme, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 572f2b2976 005/123: Fix bugs section, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 32cbd92a76 007/123: Add straight installation to readme, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 1bd018e477 015/123: Update formatting in roadmap section, ELPA Syncer, 2023/12/05
- [elpa] externals/dape 2d4c0e6748 022/123: Add file and line to stack in info buffer, ELPA Syncer, 2023/12/05
- [elpa] externals/dape d896720cc1 011/123: Add projectile configuration in readme, ELPA Syncer, 2023/12/05