@@ -175,7 +175,12 @@ strings, for the sake of launch.json feature parity."
175175 (buffer-file-name )))
176176 (module (plist-get conf :module ))
177177 (debugger (plist-get conf :debugger )))
178+ ; ; These are `dap-python' -specific and always ignored.
178179 (cl-remf conf :debugger )
180+ (cl-remf conf :target-module )
181+
182+ ; ; Ignored by ptsvd and set explicitly for debugpy.
183+ (cl-remf conf :program )
179184 (pcase (or debugger dap-python-debugger)
180185 ((or 'ptvsd " ptvsd" )
181186 (let ((host " localhost" )
@@ -184,40 +189,46 @@ strings, for the sake of launch.json feature parity."
184189 ; ; a list, so it will be mapconcat'ed, yielding the empty string.
185190 (when (sequencep python-args)
186191 (setq python-args (mapconcat #'shell-quote-argument python-args " " )))
192+ ; ; ignored by ptsvd anyway
193+ (cl-remf conf :module )
194+ (cl-remf conf :args )
187195 (plist-put conf :program-to-start
188- (format " %s%s -m ptvsd --wait --host %s --port %s%s %s %s "
196+ (format " %s%s -m ptvsd --wait --host %s --port %s%s %s%s "
189197 (or dap-python-terminal " " )
190198 (shell-quote-argument python-executable)
191199 host
192200 debug-port
193201 (if module (concat " -m " (shell-quote-argument module)) " " )
194- (shell-quote-argument program)
195- python-args))
202+ (if program ( shell-quote-argument program) " " )
203+ ( if ( not ( string-empty-p python-args)) ( concat " " python-args) " " ) ))
196204 (plist-put conf :debugServer debug-port)
197205 (plist-put conf :port debug-port)
198206 (plist-put conf :hostName host)
199207 (plist-put conf :host host)))
200208 ((or 'debugpy " debugpy" )
209+ (cond ((stringp python-args)
210+ (cl-callf split-string-and-unquote python-args))
211+ ; ; If both :module and :program are specified, we'll need to push
212+ ; ; :program to PYTHON-ARGS instead, to behave like ptvsd. This is
213+ ; ; needed for the debug-test-at-point functionality.
214+ ((and (vectorp python-args) module program)
215+ (cl-callf cl-coerce python-args 'list )))
216+
201217 ; ; If certain properties are nil, issues will arise, as debugpy expects
202218 ; ; them to unspecified instead. Some templates in this file set such
203219 ; ; properties (e.g. :module) to nil instead of leaving them undefined. To
204220 ; ; support them, sanitize CONF before passing it on.
205- (when (or (null python-args) (stringp python-args))
206- (cl-remf conf :args ))
207- (when (stringp python-args)
208- (let ((args (split-string-and-unquote python-args)))
209- (if args
210- (plist-put conf :args args)
211- ; ; :args "" -> :args nil -> {"args": null}; to handle that edge
212- ; ; case, use the empty vector instead.
213- (plist-put conf :args []))))
214- (cl-remf conf :target-module )
215- (cl-remf conf :program )
216221 (when program
217- (plist-put conf :program program))
222+ (if module
223+ (push program python-args)
224+ (plist-put conf :program program)))
225+
226+ (cl-remf conf :args )
227+ (plist-put conf :args (or python-args []))
218228
219229 (unless module
220230 (cl-remf conf :module ))
231+
221232 (unless (plist-get conf :cwd )
222233 (cl-remf conf :cwd ))
223234
@@ -226,20 +237,10 @@ strings, for the sake of launch.json feature parity."
226237 (_ (error " `dap-python' : unknown :debugger type %S " debugger)))
227238 conf))
228239
229- (defun dap-python--normalize-args (args )
230- " Convert ARGS to a `list' of arguments.
231- ARGS may be a string, a vector or a list."
232- (cl-typecase args
233- (string (split-string-and-unquote args))
234- (vector (cl-coerce args 'list ))
235- (t args)))
236-
237240(defun dap-python--populate-test-at-point (conf )
238241 " Populate CONF with the required arguments."
239242 (if-let ((test (dap-python--test-at-point)))
240- (let ((args (dap-python--normalize-args (plist-get conf :args ))))
241- (cl-remf conf :args )
242- (plist-put conf :args (cons (concat (buffer-file-name ) test) args)))
243+ (plist-put conf :program test)
243244 (user-error " `dap-python' : no test at point" ))
244245 (plist-put conf :cwd (lsp-workspace-root))
245246
@@ -268,6 +269,7 @@ ARGS may be a string, a vector or a list."
268269(dap-register-debug-template " Python :: Run pytest (at point)"
269270 (list :type " python-test-at-point"
270271 :args " "
272+ :program nil
271273 :module " pytest"
272274 :request " launch"
273275 :name " Python :: Run pytest (at point)" ))
0 commit comments