Skip to content

Commit 6b12e7b

Browse files
committed
Temp refactor
1 parent 87a69cb commit 6b12e7b

16 files changed

+801
-609
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/DebugEventHandlerService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private void PowerShellContext_RunspaceChanged(object sender, RunspaceChangedEve
9292
{
9393
if (_debugStateService.WaitingForAttach &&
9494
e.ChangeAction == RunspaceChangeAction.Enter &&
95-
e.NewRunspace.Context == RunspaceContext.DebuggedRunspace)
95+
e.NewRunspace.Context == RunspaceOrigin.DebuggedRunspace)
9696
{
9797
// Send the InitializedEvent so that the debugger will continue
9898
// sending configuration requests

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

Lines changed: 89 additions & 105 deletions
Large diffs are not rendered by default.

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ private async Task OnExecutionCompletedAsync(Task executeTask)
414414
if (_debugStateService.IsAttachSession)
415415
{
416416
// Pop the sessions
417-
if (_powerShellContextService.CurrentRunspace.Context == RunspaceContext.EnteredProcess)
417+
if (_powerShellContextService.CurrentRunspace.Context == RunspaceOrigin.EnteredProcess)
418418
{
419419
try
420420
{
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Management.Automation;
3+
using System.Management.Automation.Runspaces;
4+
using SMA = System.Management.Automation;
5+
6+
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Context
7+
{
8+
internal interface IPowerShellContext : IDisposable
9+
{
10+
SMA.PowerShell CurrentPowerShell { get; }
11+
12+
bool IsRunspacePushed { get; }
13+
14+
void SetShouldExit(int exitCode);
15+
16+
void ProcessDebuggerResult(DebuggerCommandResults debuggerResult);
17+
18+
void PushNestedPowerShell();
19+
20+
void PushPowerShell(Runspace runspaceToUse);
21+
}
22+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Context;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Management.Automation.Runspaces;
5+
using System.Runtime.CompilerServices;
6+
using System.Text;
7+
using SMA = System.Management.Automation;
8+
9+
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Context
10+
{
11+
internal class PowerShellContext : IPowerShellContext
12+
{
13+
private readonly Stack<PowerShellContextFrame> _psFrameStack;
14+
15+
public PowerShellContext()
16+
{
17+
_psFrameStack = new Stack<PowerShellContextFrame>();
18+
}
19+
20+
public SMA.PowerShell CurrentPowerShell => _psFrameStack.Peek().PowerShell;
21+
22+
private void PushFrame(PowerShellContextFrame frame)
23+
{
24+
if (_psFrameStack.Count > 0)
25+
{
26+
RemoveRunspaceEventHandlers(CurrentPowerShell.Runspace);
27+
}
28+
AddRunspaceEventHandlers(frame.PowerShell.Runspace);
29+
_psFrameStack.Push(frame);
30+
RunPowerShellLoop(frame.FrameType);
31+
}
32+
33+
private void AddRunspaceEventHandlers(Runspace runspace)
34+
{
35+
runspace.Debugger.DebuggerStop += OnDebuggerStopped;
36+
runspace.Debugger.BreakpointUpdated += OnBreakpointUpdated;
37+
runspace.StateChanged += OnRunspaceStateChanged;
38+
}
39+
40+
private void RemoveRunspaceEventHandlers(Runspace runspace)
41+
{
42+
runspace.Debugger.DebuggerStop -= OnDebuggerStopped;
43+
runspace.Debugger.BreakpointUpdated -= OnBreakpointUpdated;
44+
runspace.StateChanged -= OnRunspaceStateChanged;
45+
}
46+
}
47+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Context;
2+
using System;
3+
using System.Threading;
4+
using SMA = System.Management.Automation;
5+
6+
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Context
7+
{
8+
internal class PowerShellContextFrame : IDisposable
9+
{
10+
private bool disposedValue;
11+
12+
public PowerShellContextFrame(SMA.PowerShell powerShell, PowerShellFrameType frameType, CancellationTokenSource cancellationTokenSource)
13+
{
14+
PowerShell = powerShell;
15+
FrameType = frameType;
16+
CancellationTokenSource = cancellationTokenSource;
17+
}
18+
19+
public SMA.PowerShell PowerShell { get; }
20+
21+
public PowerShellFrameType FrameType { get; }
22+
23+
public CancellationTokenSource CancellationTokenSource { get; }
24+
25+
protected virtual void Dispose(bool disposing)
26+
{
27+
if (!disposedValue)
28+
{
29+
if (disposing)
30+
{
31+
PowerShell.Dispose();
32+
CancellationTokenSource.Dispose();
33+
}
34+
35+
disposedValue = true;
36+
}
37+
}
38+
39+
public void Dispose()
40+
{
41+
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
42+
Dispose(disposing: true);
43+
GC.SuppressFinalize(this);
44+
}
45+
}
46+
}

src/PowerShellEditorServices/Services/PowerShell/Execution/PowerShellFrameType.cs renamed to src/PowerShellEditorServices/Services/PowerShell/Context/PowerShellFrameType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22

3-
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution
3+
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Context
44
{
55
[Flags]
66
internal enum PowerShellFrameType

src/PowerShellEditorServices/Services/PowerShell/Execution/DebuggerResumingEventArgs.cs renamed to src/PowerShellEditorServices/Services/PowerShell/Debugging/DebuggerResumingEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Management.Automation;
22

3-
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution
3+
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Debugging
44
{
55
internal class DebuggerResumingEventArgs
66
{
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Management.Automation;
5+
using System.Text;
6+
using System.Threading;
7+
8+
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Debugging
9+
{
10+
internal interface IPowerShellDebugContext
11+
{
12+
bool IsStopped { get; }
13+
14+
DscBreakpointCapability DscBreakpointCapability { get; }
15+
16+
DebuggerStopEventArgs LastStopEventArgs { get; }
17+
18+
CancellationToken OnResumeCancellationToken { get; }
19+
20+
void Continue();
21+
22+
void StepOver();
23+
24+
void StepInto();
25+
26+
void StepOut();
27+
28+
void Break();
29+
30+
void Abort();
31+
}
32+
}

0 commit comments

Comments
 (0)