@@ -29,6 +29,7 @@ class Capabilities(components.Capabilities):
2929 "supportsVariablePaging" : False ,
3030 "supportsRunInTerminalRequest" : False ,
3131 "supportsMemoryReferences" : False ,
32+ "supportsArgsCanBeInterpretedByShell" : False ,
3233 }
3334
3435 class Expectations (components .Capabilities ):
@@ -364,20 +365,6 @@ def property_or_debug_option(prop_name, flag_name):
364365 '"program", "module", and "code" are mutually exclusive'
365366 )
366367
367- # Propagate "args" via CLI if and only if shell expansion is requested.
368- args_expansion = request (
369- "argsExpansion" , json .enum ("shell" , "none" , optional = True )
370- )
371- if args_expansion == "shell" :
372- args += request ("args" , json .array (str ))
373- request .arguments .pop ("args" , None )
374-
375- cwd = request ("cwd" , str , optional = True )
376- if cwd == ():
377- # If it's not specified, but we're launching a file rather than a module,
378- # and the specified path has a directory in it, use that.
379- cwd = None if program == () else (os .path .dirname (program ) or None )
380-
381368 console = request (
382369 "console" ,
383370 json .enum (
@@ -389,6 +376,30 @@ def property_or_debug_option(prop_name, flag_name):
389376 )
390377 console_title = request ("consoleTitle" , json .default ("Python Debug Console" ))
391378
379+ # Propagate "args" via CLI so that shell expansion can be applied if requested.
380+ target_args = request ("args" , json .array (str , vectorize = True ))
381+ args += target_args
382+
383+ # If "args" was a single string rather than an array, shell expansion must be applied.
384+ shell_expand_args = len (target_args ) > 0 and isinstance (
385+ request .arguments ["args" ], str
386+ )
387+ if shell_expand_args :
388+ if not self .capabilities ["supportsArgsCanBeInterpretedByShell" ]:
389+ raise request .isnt_valid (
390+ 'Shell expansion in "args" is not supported by the client'
391+ )
392+ if console == "internalConsole" :
393+ raise request .isnt_valid (
394+ 'Shell expansion in "args" is not available for "console":"internalConsole"'
395+ )
396+
397+ cwd = request ("cwd" , str , optional = True )
398+ if cwd == ():
399+ # If it's not specified, but we're launching a file rather than a module,
400+ # and the specified path has a directory in it, use that.
401+ cwd = None if program == () else (os .path .dirname (program ) or None )
402+
392403 sudo = bool (property_or_debug_option ("sudo" , "Sudo" ))
393404 if sudo and sys .platform == "win32" :
394405 raise request .cant_handle ('"sudo":true is not supported on Windows.' )
@@ -412,6 +423,7 @@ def property_or_debug_option(prop_name, flag_name):
412423 launcher_path ,
413424 adapter_host ,
414425 args ,
426+ shell_expand_args ,
415427 cwd ,
416428 console ,
417429 console_title ,
0 commit comments