5
5
using System . Collections . Generic ;
6
6
using System . Linq ;
7
7
using System . Management . Automation ;
8
+ using System . Threading ;
8
9
using System . Threading . Tasks ;
9
10
using Microsoft . Extensions . Logging ;
10
11
using Microsoft . PowerShell . EditorServices . Logging ;
11
12
using Microsoft . PowerShell . EditorServices . Services . DebugAdapter ;
13
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell ;
14
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Execution ;
15
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
12
16
13
17
namespace Microsoft . PowerShell . EditorServices . Services
14
18
{
15
19
internal class BreakpointService
16
20
{
17
21
private readonly ILogger < BreakpointService > _logger ;
18
- private readonly PowerShellContextService _powerShellContextService ;
22
+ private readonly PowerShellExecutionService _executionService ;
23
+ private readonly EditorServicesConsolePSHost _editorServicesHost ;
19
24
private readonly DebugStateService _debugStateService ;
20
25
21
26
// TODO: This needs to be managed per nested session
@@ -27,11 +32,13 @@ internal class BreakpointService
27
32
28
33
public BreakpointService (
29
34
ILoggerFactory factory ,
30
- PowerShellContextService powerShellContextService ,
35
+ PowerShellExecutionService executionService ,
36
+ EditorServicesConsolePSHost editorServicesHost ,
31
37
DebugStateService debugStateService )
32
38
{
33
39
_logger = factory . CreateLogger < BreakpointService > ( ) ;
34
- _powerShellContextService = powerShellContextService ;
40
+ _executionService = executionService ;
41
+ _editorServicesHost = editorServicesHost ;
35
42
_debugStateService = debugStateService ;
36
43
}
37
44
@@ -40,14 +47,14 @@ public async Task<List<Breakpoint>> GetBreakpointsAsync()
40
47
if ( BreakpointApiUtils . SupportsBreakpointApis )
41
48
{
42
49
return BreakpointApiUtils . GetBreakpoints (
43
- _powerShellContextService . CurrentRunspace . Runspace . Debugger ,
50
+ _editorServicesHost . Runspace . Debugger ,
44
51
_debugStateService . RunspaceId ) ;
45
52
}
46
53
47
54
// Legacy behavior
48
55
PSCommand psCommand = new PSCommand ( ) ;
49
56
psCommand . AddCommand ( @"Microsoft.PowerShell.Utility\Get-PSBreakpoint" ) ;
50
- IEnumerable < Breakpoint > breakpoints = await _powerShellContextService . ExecuteCommandAsync < Breakpoint > ( psCommand ) . ConfigureAwait ( false ) ;
57
+ IEnumerable < Breakpoint > breakpoints = await _executionService . ExecutePSCommandAsync < Breakpoint > ( psCommand , new PowerShellExecutionOptions ( ) , CancellationToken . None ) ;
51
58
return breakpoints . ToList ( ) ;
52
59
}
53
60
@@ -59,7 +66,7 @@ public async Task<IEnumerable<BreakpointDetails>> SetBreakpointsAsync(string esc
59
66
{
60
67
try
61
68
{
62
- BreakpointApiUtils . SetBreakpoint ( _powerShellContextService . CurrentRunspace . Runspace . Debugger , breakpointDetails , _debugStateService . RunspaceId ) ;
69
+ BreakpointApiUtils . SetBreakpoint ( _editorServicesHost . Runspace . Debugger , breakpointDetails , _debugStateService . RunspaceId ) ;
63
70
}
64
71
catch ( InvalidOperationException e )
65
72
{
@@ -133,7 +140,7 @@ public async Task<IEnumerable<BreakpointDetails>> SetBreakpointsAsync(string esc
133
140
if ( psCommand != null )
134
141
{
135
142
IEnumerable < Breakpoint > setBreakpoints =
136
- await _powerShellContextService . ExecuteCommandAsync < Breakpoint > ( psCommand ) . ConfigureAwait ( false ) ;
143
+ await _executionService . ExecutePSCommandAsync < Breakpoint > ( psCommand , new PowerShellExecutionOptions ( ) , CancellationToken . None ) ;
137
144
configuredBreakpoints . AddRange (
138
145
setBreakpoints . Select ( ( breakpoint ) => BreakpointDetails . Create ( breakpoint ) )
139
146
) ;
@@ -150,7 +157,7 @@ public async Task<IEnumerable<CommandBreakpointDetails>> SetCommandBreakpoints(I
150
157
{
151
158
try
152
159
{
153
- BreakpointApiUtils . SetBreakpoint ( _powerShellContextService . CurrentRunspace . Runspace . Debugger , commandBreakpointDetails , _debugStateService . RunspaceId ) ;
160
+ BreakpointApiUtils . SetBreakpoint ( _editorServicesHost . Runspace . Debugger , commandBreakpointDetails , _debugStateService . RunspaceId ) ;
154
161
}
155
162
catch ( InvalidOperationException e )
156
163
{
@@ -211,7 +218,7 @@ public async Task<IEnumerable<CommandBreakpointDetails>> SetCommandBreakpoints(I
211
218
if ( psCommand != null )
212
219
{
213
220
IEnumerable < Breakpoint > setBreakpoints =
214
- await _powerShellContextService . ExecuteCommandAsync < Breakpoint > ( psCommand ) . ConfigureAwait ( false ) ;
221
+ await _executionService . ExecutePSCommandAsync < Breakpoint > ( psCommand , new PowerShellExecutionOptions ( ) , CancellationToken . None ) ;
215
222
configuredBreakpoints . AddRange (
216
223
setBreakpoints . Select ( CommandBreakpointDetails . Create ) ) ;
217
224
}
@@ -229,13 +236,13 @@ public async Task RemoveAllBreakpointsAsync(string scriptPath = null)
229
236
if ( BreakpointApiUtils . SupportsBreakpointApis )
230
237
{
231
238
foreach ( Breakpoint breakpoint in BreakpointApiUtils . GetBreakpoints (
232
- _powerShellContextService . CurrentRunspace . Runspace . Debugger ,
239
+ _editorServicesHost . Runspace . Debugger ,
233
240
_debugStateService . RunspaceId ) )
234
241
{
235
242
if ( scriptPath == null || scriptPath == breakpoint . Script )
236
243
{
237
244
BreakpointApiUtils . RemoveBreakpoint (
238
- _powerShellContextService . CurrentRunspace . Runspace . Debugger ,
245
+ _editorServicesHost . Runspace . Debugger ,
239
246
breakpoint ,
240
247
_debugStateService . RunspaceId ) ;
241
248
}
@@ -256,7 +263,7 @@ public async Task RemoveAllBreakpointsAsync(string scriptPath = null)
256
263
257
264
psCommand . AddCommand ( @"Microsoft.PowerShell.Utility\Remove-PSBreakpoint" ) ;
258
265
259
- await _powerShellContextService . ExecuteCommandAsync < object > ( psCommand ) . ConfigureAwait ( false ) ;
266
+ await _executionService . ExecutePSCommandAsync < object > ( psCommand , new PowerShellExecutionOptions ( ) , CancellationToken . None ) . ConfigureAwait ( false ) ;
260
267
}
261
268
catch ( Exception e )
262
269
{
@@ -271,7 +278,7 @@ public async Task RemoveBreakpointsAsync(IEnumerable<Breakpoint> breakpoints)
271
278
foreach ( Breakpoint breakpoint in breakpoints )
272
279
{
273
280
BreakpointApiUtils . RemoveBreakpoint (
274
- _powerShellContextService . CurrentRunspace . Runspace . Debugger ,
281
+ _editorServicesHost . Runspace . Debugger ,
275
282
breakpoint ,
276
283
_debugStateService . RunspaceId ) ;
277
284
@@ -302,7 +309,7 @@ public async Task RemoveBreakpointsAsync(IEnumerable<Breakpoint> breakpoints)
302
309
psCommand . AddCommand ( @"Microsoft.PowerShell.Utility\Remove-PSBreakpoint" ) ;
303
310
psCommand . AddParameter ( "Id" , breakpoints . Select ( b => b . Id ) . ToArray ( ) ) ;
304
311
305
- await _powerShellContextService . ExecuteCommandAsync < object > ( psCommand ) . ConfigureAwait ( false ) ;
312
+ await _executionService . ExecutePSCommandAsync < object > ( psCommand , new PowerShellExecutionOptions ( ) , CancellationToken . None ) ;
306
313
}
307
314
}
308
315
0 commit comments