@@ -177,7 +177,8 @@ strings, for the sake of launch.json feature parity."
177
177
(plist-get conf :program )
178
178
(buffer-file-name )))
179
179
(module (plist-get conf :module ))
180
- (debugger (plist-get conf :debugger )))
180
+ (debugger (plist-get conf :debugger ))
181
+ (targetPid (plist-get conf :processId )))
181
182
; ; These are `dap-python' -specific and always ignored.
182
183
(cl-remf conf :debugger )
183
184
(cl-remf conf :target-module )
@@ -196,14 +197,17 @@ strings, for the sake of launch.json feature parity."
196
197
(cl-remf conf :module )
197
198
(cl-remf conf :args )
198
199
(plist-put conf :program-to-start
199
- (format " %s%s -m ptvsd --wait --host %s --port %s%s %s %s"
200
+ (format " %s%s -m ptvsd --wait --host %s --port %s %s "
200
201
(or dap-python-terminal " " )
201
202
(shell-quote-argument python-executable)
202
203
host
203
204
debug-port
204
- (if module (concat " -m " (shell-quote-argument module)) " " )
205
- (if program (shell-quote-argument program) " " )
206
- (if (not (string-empty-p python-args)) (concat " " python-args) " " )))
205
+ (if targetPid
206
+ (format " --pid %s " targetPid)
207
+ (format " %s %s %s "
208
+ (if module (concat " -m " (shell-quote-argument module)) " " )
209
+ (if program (shell-quote-argument program) " " )
210
+ (if (not (string-empty-p python-args)) (concat " " python-args) " " )))))
207
211
(plist-put conf :debugServer debug-port)
208
212
(plist-put conf :port debug-port)
209
213
(plist-put conf :hostName host)
@@ -235,11 +239,12 @@ strings, for the sake of launch.json feature parity."
235
239
(unless (plist-get conf :cwd )
236
240
(cl-remf conf :cwd ))
237
241
238
- (pcase (plist-get conf :request )
239
- (" launch"
242
+ (pcase (cons (plist-get conf :request ) targetPid)
243
+ ((or `(" launch" . nil )
244
+ `(" attach" . ,(and pid (guard pid))))
240
245
(plist-put conf :dap-server-path
241
246
(list python-executable " -m" " debugpy.adapter" )))
242
- (" attach"
247
+ (`( " attach" . nil )
243
248
(let* ((connect (plist-get conf :connect ))
244
249
(host (or (plist-get connect :host ) " localhost" ))
245
250
(port (or (plist-get connect :port ) 5678 )))
@@ -260,6 +265,11 @@ strings, for the sake of launch.json feature parity."
260
265
(dap-python--populate-start-file-args conf))
261
266
262
267
(dap-register-debug-provider " python" 'dap-python--populate-start-file-args )
268
+ (dap-register-debug-template " Python :: Attach to running process"
269
+ (list :type " python"
270
+ :request " attach"
271
+ :processId " ${command:pickProcess}"
272
+ :name " Python :: Attach to running process" ))
263
273
(dap-register-debug-template " Python :: Run file (buffer)"
264
274
(list :type " python"
265
275
:args " "
0 commit comments