@@ -43,6 +43,8 @@ internal class DebugService
43
43
44
44
private readonly EditorServicesConsolePSHost _psesHost ;
45
45
46
+ private readonly IPowerShellDebugContext _debugContext ;
47
+
46
48
private int nextVariableId ;
47
49
private string temporaryScriptListingPath ;
48
50
private List < VariableDetailsBase > variables ;
@@ -68,7 +70,7 @@ internal class DebugService
68
70
/// Gets a boolean that indicates whether the debugger is currently
69
71
/// stopped at a breakpoint.
70
72
/// </summary>
71
- public bool IsDebuggerStopped => _executionService . DebugContext . IsStopped ;
73
+ public bool IsDebuggerStopped => _debugContext . IsStopped ;
72
74
73
75
/// <summary>
74
76
/// Gets the current DebuggerStoppedEventArgs when the debugger
@@ -106,6 +108,7 @@ internal class DebugService
106
108
/// <param name="logger">An ILogger implementation used for writing log messages.</param>
107
109
public DebugService (
108
110
PowerShellExecutionService executionService ,
111
+ IPowerShellDebugContext debugContext ,
109
112
RemoteFileManagerService remoteFileManager ,
110
113
BreakpointService breakpointService ,
111
114
EditorServicesConsolePSHost psesHost ,
@@ -117,9 +120,10 @@ public DebugService(
117
120
_executionService = executionService ;
118
121
_breakpointService = breakpointService ;
119
122
_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 ;
123
127
124
128
this . remoteFileManager = remoteFileManager ;
125
129
@@ -146,11 +150,11 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
146
150
BreakpointDetails [ ] breakpoints ,
147
151
bool clearExisting = true )
148
152
{
149
- DscBreakpointCapability dscBreakpoints = _executionService . CurrentRunspace . DscBreakpointCapability ;
153
+ DscBreakpointCapability dscBreakpoints = await _debugContext . GetDscBreakpointCapabilityAsync ( CancellationToken . None ) ;
150
154
151
155
string scriptPath = scriptFile . FilePath ;
152
156
// Make sure we're using the remote script path
153
- if ( _psesHost . Runspace . RunspaceIsRemote
157
+ if ( _psesHost . CurrentRunspace . IsOnRemoteMachine
154
158
&& this . remoteFileManager != null )
155
159
{
156
160
if ( ! this . remoteFileManager . IsUnderRemoteTempPath ( scriptPath ) )
@@ -164,7 +168,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
164
168
string mappedPath =
165
169
this . remoteFileManager . GetMappedPath (
166
170
scriptPath ,
167
- _executionService . CurrentRunspace ) ;
171
+ _psesHost . CurrentRunspace ) ;
168
172
169
173
scriptPath = mappedPath ;
170
174
}
@@ -229,31 +233,31 @@ public async Task<CommandBreakpointDetails[]> SetCommandBreakpointsAsync(
229
233
/// </summary>
230
234
public void Continue ( )
231
235
{
232
- _executionService . DebugContext . Continue ( ) ;
236
+ _debugContext . Continue ( ) ;
233
237
}
234
238
235
239
/// <summary>
236
240
/// Sends a "step over" action to the debugger when stopped.
237
241
/// </summary>
238
242
public void StepOver ( )
239
243
{
240
- _executionService . DebugContext . StepOver ( ) ;
244
+ _debugContext . StepOver ( ) ;
241
245
}
242
246
243
247
/// <summary>
244
248
/// Sends a "step in" action to the debugger when stopped.
245
249
/// </summary>
246
250
public void StepIn ( )
247
251
{
248
- _executionService . DebugContext . StepInto ( ) ;
252
+ _debugContext . StepInto ( ) ;
249
253
}
250
254
251
255
/// <summary>
252
256
/// Sends a "step out" action to the debugger when stopped.
253
257
/// </summary>
254
258
public void StepOut ( )
255
259
{
256
- _executionService . DebugContext . StepOut ( ) ;
260
+ _debugContext . StepOut ( ) ;
257
261
}
258
262
259
263
/// <summary>
@@ -263,7 +267,7 @@ public void StepOut()
263
267
/// </summary>
264
268
public void Break ( )
265
269
{
266
- _executionService . DebugContext . BreakExecution ( ) ;
270
+ _debugContext . BreakExecution ( ) ;
267
271
}
268
272
269
273
/// <summary>
@@ -272,7 +276,7 @@ public void Break()
272
276
/// </summary>
273
277
public void Abort ( )
274
278
{
275
- _executionService . DebugContext . Abort ( ) ;
279
+ _debugContext . Abort ( ) ;
276
280
}
277
281
278
282
/// <summary>
@@ -809,7 +813,7 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
809
813
810
814
// When debugging, this is the best way I can find to get what is likely the workspace root.
811
815
// This is controlled by the "cwd:" setting in the launch config.
812
- string workspaceRootPath = _executionService . PowerShellContext . InitialWorkingDirectory ;
816
+ string workspaceRootPath = _psesHost . InitialWorkingDirectory ;
813
817
814
818
this . stackFrameDetails [ i ] =
815
819
StackFrameDetails . Create ( callStackFrames [ i ] , autoVariables , localVariables , workspaceRootPath ) ;
@@ -820,14 +824,14 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
820
824
{
821
825
this . stackFrameDetails [ i ] . ScriptPath = scriptNameOverride ;
822
826
}
823
- else if ( _executionService . CurrentRunspace . IsRemote ( )
827
+ else if ( _psesHost . CurrentRunspace . IsOnRemoteMachine
824
828
&& this . remoteFileManager != null
825
829
&& ! string . Equals ( stackFrameScriptPath , StackFrameDetails . NoFileScriptPath ) )
826
830
{
827
831
this . stackFrameDetails [ i ] . ScriptPath =
828
832
this . remoteFileManager . GetMappedPath (
829
833
stackFrameScriptPath ,
830
- _executionService . CurrentRunspace ) ;
834
+ _psesHost . CurrentRunspace ) ;
831
835
}
832
836
}
833
837
}
@@ -889,9 +893,9 @@ await _executionService.ExecutePSCommandAsync<PSObject>(
889
893
890
894
this . temporaryScriptListingPath =
891
895
this . remoteFileManager . CreateTemporaryFile (
892
- $ "[{ _executionService . CurrentRunspace . SessionDetails . ComputerName } ] { TemporaryScriptFileName } ",
896
+ $ "[{ _psesHost . CurrentRunspace . SessionDetails . ComputerName } ] { TemporaryScriptFileName } ",
893
897
scriptListing ,
894
- _executionService . CurrentRunspace ) ;
898
+ _psesHost . CurrentRunspace ) ;
895
899
896
900
localScriptPath =
897
901
this . temporaryScriptListingPath
@@ -911,14 +915,14 @@ await this.FetchStackFramesAndVariablesAsync(
911
915
912
916
// If this is a remote connection and the debugger stopped at a line
913
917
// in a script file, get the file contents
914
- if ( _executionService . CurrentRunspace . IsRemote ( )
918
+ if ( _psesHost . CurrentRunspace . IsOnRemoteMachine
915
919
&& this . remoteFileManager != null
916
920
&& ! noScriptName )
917
921
{
918
922
localScriptPath =
919
923
await this . remoteFileManager . FetchRemoteFileAsync (
920
924
e . InvocationInfo . ScriptName ,
921
- _executionService . CurrentRunspace ) . ConfigureAwait ( false ) ;
925
+ _psesHost . CurrentRunspace ) . ConfigureAwait ( false ) ;
922
926
}
923
927
924
928
if ( this . stackFrameDetails . Length > 0 )
@@ -938,7 +942,7 @@ await this.remoteFileManager.FetchRemoteFileAsync(
938
942
this . CurrentDebuggerStoppedEventArgs =
939
943
new DebuggerStoppedEventArgs (
940
944
e ,
941
- _executionService . CurrentRunspace ,
945
+ _psesHost . CurrentRunspace ,
942
946
localScriptPath ) ;
943
947
944
948
// Notify the host that the debugger is stopped
@@ -967,13 +971,13 @@ private void OnBreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
967
971
if ( e . Breakpoint is LineBreakpoint lineBreakpoint )
968
972
{
969
973
string scriptPath = lineBreakpoint . Script ;
970
- if ( _executionService . CurrentRunspace . IsRemote ( )
974
+ if ( _psesHost . CurrentRunspace . IsOnRemoteMachine
971
975
&& this . remoteFileManager != null )
972
976
{
973
977
string mappedPath =
974
978
this . remoteFileManager . GetMappedPath (
975
979
scriptPath ,
976
- _executionService . CurrentRunspace ) ;
980
+ _psesHost . CurrentRunspace ) ;
977
981
978
982
if ( mappedPath == null )
979
983
{
0 commit comments