@@ -140,14 +140,14 @@ public LaunchAndAttachHandler(
140
140
141
141
public async Task < LaunchResponse > Handle ( PsesLaunchRequestArguments request , CancellationToken cancellationToken )
142
142
{
143
- _debugService . SetPathMappings ( request . PathMappings ) ;
143
+ _debugService . PathMappings = request . PathMappings ;
144
144
try
145
145
{
146
146
return await HandleImpl ( request , cancellationToken ) . ConfigureAwait ( false ) ;
147
147
}
148
148
catch
149
149
{
150
- _debugService . UnsetPathMappings ( ) ;
150
+ _debugService . PathMappings = [ ] ;
151
151
throw ;
152
152
}
153
153
}
@@ -230,38 +230,11 @@ await _executionService.ExecutePSCommandAsync(
230
230
231
231
// Store the launch parameters so that they can be used later
232
232
_debugStateService . NoDebug = request . NoDebug ;
233
- _debugStateService . ScriptToLaunch = request . Script ;
233
+ _debugStateService . ScriptToLaunch = GetLaunchScript ( request ) ;
234
234
_debugStateService . Arguments = request . Args ;
235
235
_debugStateService . IsUsingTempIntegratedConsole = request . CreateTemporaryIntegratedConsole ;
236
236
_debugStateService . ExecuteMode = request . ExecuteMode ;
237
237
238
- if ( request . CreateTemporaryIntegratedConsole
239
- && ! string . IsNullOrEmpty ( request . Script )
240
- && ScriptFile . IsUntitledPath ( request . Script ) )
241
- {
242
- throw new RpcErrorException ( 0 , null , "Running an Untitled file in a temporary Extension Terminal is currently not supported!" ) ;
243
- }
244
-
245
- // If the current session is remote, map the script path to the remote
246
- // machine if necessary
247
- if ( _debugStateService . ScriptToLaunch != null
248
- && _runspaceContext . CurrentRunspace . IsOnRemoteMachine )
249
- {
250
- if ( _debugService . TryGetMappedRemotePath ( _debugStateService . ScriptToLaunch , out string remoteMappedPath ) )
251
- {
252
- _debugStateService . ScriptToLaunch = remoteMappedPath ;
253
- }
254
- else
255
- {
256
- // If the script is not mapped, we will map it to the remote path
257
- // using the RemoteFileManagerService.
258
- _debugStateService . ScriptToLaunch =
259
- _remoteFileManagerService . GetMappedPath (
260
- _debugStateService . ScriptToLaunch ,
261
- _runspaceContext . CurrentRunspace ) ;
262
- }
263
- }
264
-
265
238
// If no script is being launched, mark this as an interactive
266
239
// debugging session
267
240
_debugStateService . IsInteractiveDebugSession = string . IsNullOrEmpty ( _debugStateService . ScriptToLaunch ) ;
@@ -284,13 +257,13 @@ public async Task<AttachResponse> Handle(PsesAttachRequestArguments request, Can
284
257
_debugService . IsDebuggingRemoteRunspace = true ;
285
258
try
286
259
{
287
- _debugService . SetPathMappings ( request . PathMappings ) ;
260
+ _debugService . PathMappings = request . PathMappings ;
288
261
return await HandleImpl ( request , cancellationToken ) . ConfigureAwait ( false ) ;
289
262
}
290
263
catch
291
264
{
292
265
_debugService . IsDebuggingRemoteRunspace = false ;
293
- _debugService . UnsetPathMappings ( ) ;
266
+ _debugService . PathMappings = [ ] ;
294
267
throw ;
295
268
}
296
269
}
@@ -522,7 +495,7 @@ private async Task OnExecutionCompletedAsync(Task executeTask)
522
495
_debugEventHandlerService . UnregisterEventHandlers ( ) ;
523
496
524
497
_debugService . IsDebuggingRemoteRunspace = false ;
525
- _debugService . UnsetPathMappings ( ) ;
498
+ _debugService . PathMappings = [ ] ;
526
499
527
500
if ( ! isRunspaceClosed && _debugStateService . IsAttachSession )
528
501
{
@@ -552,5 +525,36 @@ await _executionService.ExecutePSCommandAsync(
552
525
_debugService . IsClientAttached = false ;
553
526
_debugAdapterServer . SendNotification ( EventNames . Terminated ) ;
554
527
}
528
+
529
+ private string GetLaunchScript ( PsesLaunchRequestArguments request )
530
+ {
531
+ string scriptToLaunch = request . Script ;
532
+ if ( request . CreateTemporaryIntegratedConsole
533
+ && ! string . IsNullOrEmpty ( scriptToLaunch )
534
+ && ScriptFile . IsUntitledPath ( scriptToLaunch ) )
535
+ {
536
+ throw new RpcErrorException ( 0 , null , "Running an Untitled file in a temporary Extension Terminal is currently not supported!" ) ;
537
+ }
538
+
539
+ // If the current session is remote, map the script path to the remote
540
+ // machine if necessary
541
+ if ( scriptToLaunch is not null && _runspaceContext . CurrentRunspace . IsOnRemoteMachine )
542
+ {
543
+ if ( _debugService . TryGetMappedRemotePath ( scriptToLaunch , out string remoteMappedPath ) )
544
+ {
545
+ scriptToLaunch = remoteMappedPath ;
546
+ }
547
+ else
548
+ {
549
+ // If the script is not mapped, we will map it to the remote path
550
+ // using the RemoteFileManagerService.
551
+ scriptToLaunch = _remoteFileManagerService . GetMappedPath (
552
+ scriptToLaunch ,
553
+ _runspaceContext . CurrentRunspace ) ;
554
+ }
555
+ }
556
+
557
+ return scriptToLaunch ;
558
+ }
555
559
}
556
560
}
0 commit comments