@@ -43,6 +43,8 @@ internal class DebugService
4343
4444 private readonly EditorServicesConsolePSHost _psesHost ;
4545
46+ private readonly IPowerShellDebugContext _debugContext ;
47+
4648 private int nextVariableId ;
4749 private string temporaryScriptListingPath ;
4850 private List < VariableDetailsBase > variables ;
@@ -68,7 +70,7 @@ internal class DebugService
6870 /// Gets a boolean that indicates whether the debugger is currently
6971 /// stopped at a breakpoint.
7072 /// </summary>
71- public bool IsDebuggerStopped => _executionService . DebugContext . IsStopped ;
73+ public bool IsDebuggerStopped => _debugContext . IsStopped ;
7274
7375 /// <summary>
7476 /// Gets the current DebuggerStoppedEventArgs when the debugger
@@ -106,6 +108,7 @@ internal class DebugService
106108 /// <param name="logger">An ILogger implementation used for writing log messages.</param>
107109 public DebugService (
108110 PowerShellExecutionService executionService ,
111+ IPowerShellDebugContext debugContext ,
109112 RemoteFileManagerService remoteFileManager ,
110113 BreakpointService breakpointService ,
111114 EditorServicesConsolePSHost psesHost ,
@@ -117,9 +120,10 @@ public DebugService(
117120 _executionService = executionService ;
118121 _breakpointService = breakpointService ;
119122 _psesHost = psesHost ;
120- _executionService . DebugContext . DebuggerStopped += this . OnDebuggerStopAsync ;
121- _executionService . DebugContext . DebuggerResuming += this . OnDebuggerResuming ;
122- _executionService . DebugContext . BreakpointUpdated += this . OnBreakpointUpdated ;
123+ _debugContext = debugContext ;
124+ _debugContext . DebuggerStopped += OnDebuggerStopAsync ;
125+ _debugContext . DebuggerResuming += OnDebuggerResuming ;
126+ _debugContext . BreakpointUpdated += OnBreakpointUpdated ;
123127
124128 this . remoteFileManager = remoteFileManager ;
125129
@@ -146,11 +150,11 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
146150 BreakpointDetails [ ] breakpoints ,
147151 bool clearExisting = true )
148152 {
149- DscBreakpointCapability dscBreakpoints = _executionService . CurrentRunspace . DscBreakpointCapability ;
153+ DscBreakpointCapability dscBreakpoints = await _debugContext . GetDscBreakpointCapabilityAsync ( CancellationToken . None ) ;
150154
151155 string scriptPath = scriptFile . FilePath ;
152156 // Make sure we're using the remote script path
153- if ( _psesHost . Runspace . RunspaceIsRemote
157+ if ( _psesHost . CurrentRunspace . IsOnRemoteMachine
154158 && this . remoteFileManager != null )
155159 {
156160 if ( ! this . remoteFileManager . IsUnderRemoteTempPath ( scriptPath ) )
@@ -164,7 +168,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
164168 string mappedPath =
165169 this . remoteFileManager . GetMappedPath (
166170 scriptPath ,
167- _executionService . CurrentRunspace ) ;
171+ _psesHost . CurrentRunspace ) ;
168172
169173 scriptPath = mappedPath ;
170174 }
@@ -229,31 +233,31 @@ public async Task<CommandBreakpointDetails[]> SetCommandBreakpointsAsync(
229233 /// </summary>
230234 public void Continue ( )
231235 {
232- _executionService . DebugContext . Continue ( ) ;
236+ _debugContext . Continue ( ) ;
233237 }
234238
235239 /// <summary>
236240 /// Sends a "step over" action to the debugger when stopped.
237241 /// </summary>
238242 public void StepOver ( )
239243 {
240- _executionService . DebugContext . StepOver ( ) ;
244+ _debugContext . StepOver ( ) ;
241245 }
242246
243247 /// <summary>
244248 /// Sends a "step in" action to the debugger when stopped.
245249 /// </summary>
246250 public void StepIn ( )
247251 {
248- _executionService . DebugContext . StepInto ( ) ;
252+ _debugContext . StepInto ( ) ;
249253 }
250254
251255 /// <summary>
252256 /// Sends a "step out" action to the debugger when stopped.
253257 /// </summary>
254258 public void StepOut ( )
255259 {
256- _executionService . DebugContext . StepOut ( ) ;
260+ _debugContext . StepOut ( ) ;
257261 }
258262
259263 /// <summary>
@@ -263,7 +267,7 @@ public void StepOut()
263267 /// </summary>
264268 public void Break ( )
265269 {
266- _executionService . DebugContext . BreakExecution ( ) ;
270+ _debugContext . BreakExecution ( ) ;
267271 }
268272
269273 /// <summary>
@@ -272,7 +276,7 @@ public void Break()
272276 /// </summary>
273277 public void Abort ( )
274278 {
275- _executionService . DebugContext . Abort ( ) ;
279+ _debugContext . Abort ( ) ;
276280 }
277281
278282 /// <summary>
@@ -809,7 +813,7 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
809813
810814 // When debugging, this is the best way I can find to get what is likely the workspace root.
811815 // This is controlled by the "cwd:" setting in the launch config.
812- string workspaceRootPath = _executionService . PowerShellContext . InitialWorkingDirectory ;
816+ string workspaceRootPath = _psesHost . InitialWorkingDirectory ;
813817
814818 this . stackFrameDetails [ i ] =
815819 StackFrameDetails . Create ( callStackFrames [ i ] , autoVariables , localVariables , workspaceRootPath ) ;
@@ -820,14 +824,14 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
820824 {
821825 this . stackFrameDetails [ i ] . ScriptPath = scriptNameOverride ;
822826 }
823- else if ( _executionService . CurrentRunspace . IsRemote ( )
827+ else if ( _psesHost . CurrentRunspace . IsOnRemoteMachine
824828 && this . remoteFileManager != null
825829 && ! string . Equals ( stackFrameScriptPath , StackFrameDetails . NoFileScriptPath ) )
826830 {
827831 this . stackFrameDetails [ i ] . ScriptPath =
828832 this . remoteFileManager . GetMappedPath (
829833 stackFrameScriptPath ,
830- _executionService . CurrentRunspace ) ;
834+ _psesHost . CurrentRunspace ) ;
831835 }
832836 }
833837 }
@@ -889,9 +893,9 @@ await _executionService.ExecutePSCommandAsync<PSObject>(
889893
890894 this . temporaryScriptListingPath =
891895 this . remoteFileManager . CreateTemporaryFile (
892- $ "[{ _executionService . CurrentRunspace . SessionDetails . ComputerName } ] { TemporaryScriptFileName } ",
896+ $ "[{ _psesHost . CurrentRunspace . SessionDetails . ComputerName } ] { TemporaryScriptFileName } ",
893897 scriptListing ,
894- _executionService . CurrentRunspace ) ;
898+ _psesHost . CurrentRunspace ) ;
895899
896900 localScriptPath =
897901 this . temporaryScriptListingPath
@@ -911,14 +915,14 @@ await this.FetchStackFramesAndVariablesAsync(
911915
912916 // If this is a remote connection and the debugger stopped at a line
913917 // in a script file, get the file contents
914- if ( _executionService . CurrentRunspace . IsRemote ( )
918+ if ( _psesHost . CurrentRunspace . IsOnRemoteMachine
915919 && this . remoteFileManager != null
916920 && ! noScriptName )
917921 {
918922 localScriptPath =
919923 await this . remoteFileManager . FetchRemoteFileAsync (
920924 e . InvocationInfo . ScriptName ,
921- _executionService . CurrentRunspace ) . ConfigureAwait ( false ) ;
925+ _psesHost . CurrentRunspace ) . ConfigureAwait ( false ) ;
922926 }
923927
924928 if ( this . stackFrameDetails . Length > 0 )
@@ -938,7 +942,7 @@ await this.remoteFileManager.FetchRemoteFileAsync(
938942 this . CurrentDebuggerStoppedEventArgs =
939943 new DebuggerStoppedEventArgs (
940944 e ,
941- _executionService . CurrentRunspace ,
945+ _psesHost . CurrentRunspace ,
942946 localScriptPath ) ;
943947
944948 // Notify the host that the debugger is stopped
@@ -967,13 +971,13 @@ private void OnBreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
967971 if ( e . Breakpoint is LineBreakpoint lineBreakpoint )
968972 {
969973 string scriptPath = lineBreakpoint . Script ;
970- if ( _executionService . CurrentRunspace . IsRemote ( )
974+ if ( _psesHost . CurrentRunspace . IsOnRemoteMachine
971975 && this . remoteFileManager != null )
972976 {
973977 string mappedPath =
974978 this . remoteFileManager . GetMappedPath (
975979 scriptPath ,
976- _executionService . CurrentRunspace ) ;
980+ _psesHost . CurrentRunspace ) ;
977981
978982 if ( mappedPath == null )
979983 {
0 commit comments