Skip to content

Commit 3b12bf5

Browse files
Attach to remote Python (debugpy) adapter (#451)
* Attach to remote Python (debugpy) adapter - Set :host and :debugServer instead of :dap-server-path for attach requests. - Read launch config using 'vector for json-array-type to preserve structure of pathMappings across json-encode for the subsequent attach command. * Use 'vector instead of Try Co-authored-by: Nikita Bloshchanevich <[email protected]> Co-authored-by: Nikita Bloshchanevich <[email protected]>
1 parent 2cb49bb commit 3b12bf5

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

dap-launch.el

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,32 @@ Yields nil if it cannot be found or there is no project."
5959
"Parse the project's launch.json as json data and return the result."
6060
(when-let ((launch-json (dap-launch-find-launch-json))
6161
(json-object-type 'plist)
62-
(json-array-type 'list))
62+
;; Use 'vector instead of 'list. With 'list for array type,
63+
;; json-encode-list interpreted a list with one plist element as
64+
;; an alist. Using 'list, it turned the following value of
65+
;; pathMappings:
66+
;;
67+
;; "pathMappings": [
68+
;; {
69+
;; "localRoot": "${workspaceFolder}",
70+
;; "remoteRoot": "."
71+
;; }
72+
;; ]
73+
;;
74+
;; into:
75+
;;
76+
;; ((:localRoot "${workspaceFolder}" :remoteRoot "."))
77+
;;
78+
;; and then into:
79+
;;
80+
;; "pathMappings": {
81+
;; "localRoot": [
82+
;; "${workspaceFolder}",
83+
;; "remoteRoot",
84+
;; "."
85+
;; ]
86+
;; }
87+
(json-array-type 'vector))
6388
(with-temp-buffer
6489
;; NOTE: insert-file-contents does not move point
6590
(insert-file-contents launch-json)

dap-python.el

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,18 @@ strings, for the sake of launch.json feature parity."
233233
(unless (plist-get conf :cwd)
234234
(cl-remf conf :cwd))
235235

236-
(plist-put conf :dap-server-path
237-
(list python-executable "-m" "debugpy.adapter")))
236+
(pcase (plist-get conf :request)
237+
("launch"
238+
(plist-put conf :dap-server-path
239+
(list python-executable "-m" "debugpy.adapter")))
240+
("attach"
241+
(let* ((connect (plist-get conf :connect))
242+
(host (or (plist-get connect :host) "localhost"))
243+
(port (or (plist-get connect :port) 5678)))
244+
(plist-put conf :host host)
245+
(plist-put conf :debugServer port)
246+
(cl-remf conf :connect)))))
247+
238248
(_ (error "`dap-python': unknown :debugger type %S" debugger)))
239249
conf))
240250

0 commit comments

Comments
 (0)