@@ -140,14 +140,14 @@ public LaunchAndAttachHandler(
140140
141141 public async Task < LaunchResponse > Handle ( PsesLaunchRequestArguments request , CancellationToken cancellationToken )
142142 {
143- _debugService . SetPathMappings ( request . PathMappings ) ;
143+ _debugService . PathMappings = request . PathMappings ;
144144 try
145145 {
146146 return await HandleImpl ( request , cancellationToken ) . ConfigureAwait ( false ) ;
147147 }
148148 catch
149149 {
150- _debugService . UnsetPathMappings ( ) ;
150+ _debugService . PathMappings = [ ] ;
151151 throw ;
152152 }
153153 }
@@ -230,38 +230,11 @@ await _executionService.ExecutePSCommandAsync(
230230
231231 // Store the launch parameters so that they can be used later
232232 _debugStateService . NoDebug = request . NoDebug ;
233- _debugStateService . ScriptToLaunch = request . Script ;
233+ _debugStateService . ScriptToLaunch = GetLaunchScript ( request ) ;
234234 _debugStateService . Arguments = request . Args ;
235235 _debugStateService . IsUsingTempIntegratedConsole = request . CreateTemporaryIntegratedConsole ;
236236 _debugStateService . ExecuteMode = request . ExecuteMode ;
237237
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-
265238 // If no script is being launched, mark this as an interactive
266239 // debugging session
267240 _debugStateService . IsInteractiveDebugSession = string . IsNullOrEmpty ( _debugStateService . ScriptToLaunch ) ;
@@ -284,13 +257,13 @@ public async Task<AttachResponse> Handle(PsesAttachRequestArguments request, Can
284257 _debugService . IsDebuggingRemoteRunspace = true ;
285258 try
286259 {
287- _debugService . SetPathMappings ( request . PathMappings ) ;
260+ _debugService . PathMappings = request . PathMappings ;
288261 return await HandleImpl ( request , cancellationToken ) . ConfigureAwait ( false ) ;
289262 }
290263 catch
291264 {
292265 _debugService . IsDebuggingRemoteRunspace = false ;
293- _debugService . UnsetPathMappings ( ) ;
266+ _debugService . PathMappings = [ ] ;
294267 throw ;
295268 }
296269 }
@@ -522,7 +495,7 @@ private async Task OnExecutionCompletedAsync(Task executeTask)
522495 _debugEventHandlerService . UnregisterEventHandlers ( ) ;
523496
524497 _debugService . IsDebuggingRemoteRunspace = false ;
525- _debugService . UnsetPathMappings ( ) ;
498+ _debugService . PathMappings = [ ] ;
526499
527500 if ( ! isRunspaceClosed && _debugStateService . IsAttachSession )
528501 {
@@ -552,5 +525,36 @@ await _executionService.ExecutePSCommandAsync(
552525 _debugService . IsClientAttached = false ;
553526 _debugAdapterServer . SendNotification ( EventNames . Terminated ) ;
554527 }
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+ }
555559 }
556560}
0 commit comments