@@ -102,35 +102,13 @@ public Task<ConfigurationDoneResponse> Handle(ConfigurationDoneArguments request
102
102
103
103
private async Task LaunchScriptAsync ( string scriptToLaunch )
104
104
{
105
- PSCommand cmd ;
106
- if ( ScriptFile . IsUntitledPath ( scriptToLaunch ) )
107
- {
108
- ScriptFile untitledScript = _workspaceService . GetFile ( scriptToLaunch ) ;
109
- if ( BreakpointApiUtils . SupportsBreakpointApis ( _runspaceContext . CurrentRunspace ) )
110
- {
111
- // Parse untitled files with their `Untitled:` URI as the file name which will
112
- // cache the URI and contents within the PowerShell parser. By doing this, we
113
- // light up the ability to debug Untitled files with breakpoints. This is only
114
- // possible via the direct usage of the breakpoint APIs in PowerShell because
115
- // Set-PSBreakpoint validates that paths are actually on the filesystem.
116
- ScriptBlockAst ast = Parser . ParseInput (
117
- untitledScript . Contents ,
118
- untitledScript . DocumentUri . ToString ( ) ,
119
- out _ ,
120
- out _ ) ;
121
- // TODO: This breaks the ability to debug untitled files with breakpoints.
122
- cmd = PSCommandHelpers . BuildCommandFromArguments ( ast . GetScriptBlock ( ) . ToString ( ) , _debugStateService . Arguments , isScriptBlock : true ) ;
123
- }
124
- else
125
- {
126
- cmd = PSCommandHelpers . BuildCommandFromArguments ( untitledScript . Contents , _debugStateService . Arguments , isScriptBlock : true ) ;
127
- }
128
- }
129
- else
130
- {
131
- cmd = PSCommandHelpers . BuildCommandFromArguments ( scriptToLaunch , _debugStateService . Arguments , isScriptBlock : false ) ;
132
- }
133
-
105
+ // TODO: Theoretically we can make PowerShell respect line breakpoints in untitled
106
+ // files, but the previous method was a hack that conflicted with correct passing of
107
+ // arguments to the debugged script. We are prioritizing the latter over the former, as
108
+ // command breakpoints and `Wait-Debugger` work fine.
109
+ PSCommand cmd = ScriptFile . IsUntitledPath ( scriptToLaunch )
110
+ ? PSCommandHelpers . BuildCommandFromArguments ( string . Concat ( "{ " , _workspaceService . GetFile ( scriptToLaunch ) . Contents , " }" ) , _debugStateService . Arguments )
111
+ : PSCommandHelpers . BuildCommandFromArguments ( string . Concat ( '"' , scriptToLaunch , '"' ) , _debugStateService . Arguments ) ;
134
112
await _executionService . ExecutePSCommandAsync ( cmd , CancellationToken . None , s_debuggerExecutionOptions ) . ConfigureAwait ( false ) ;
135
113
_debugAdapterServer . SendNotification ( EventNames . Terminated ) ;
136
114
}
0 commit comments