Skip to content

Commit 06b9040

Browse files
implement powerShell/startDebugger (#1049)
* implement powerShell/startDebugger * add line Co-Authored-By: Patrick Meinecke <SeeminglyScience@users.noreply.github.com>
1 parent 7f93bf9 commit 06b9040

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

src/PowerShellEditorServices/Server/PsesDebugServer.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class PsesDebugServer : IDisposable
2424

2525
private IJsonRpcServer _jsonRpcServer;
2626

27+
private PowerShellContextService _powerShellContextService;
28+
2729
public PsesDebugServer(
2830
ILoggerFactory factory,
2931
Stream inputStream,
@@ -42,8 +44,14 @@ public async Task StartAsync(IServiceProvider languageServerServiceProvider)
4244
options.Reciever = new DapReciever();
4345
options.LoggerFactory = _loggerFactory;
4446
ILogger logger = options.LoggerFactory.CreateLogger("DebugOptionsStartup");
47+
48+
// We need to let the PowerShell Context Service know that we are in a debug session
49+
// so that it doesn't send the powerShell/startDebugger message.
50+
_powerShellContextService = languageServerServiceProvider.GetService<PowerShellContextService>();
51+
_powerShellContextService.IsDebugServerActive = true;
52+
4553
options.Services = new ServiceCollection()
46-
.AddSingleton(languageServerServiceProvider.GetService<PowerShellContextService>())
54+
.AddSingleton(_powerShellContextService)
4755
.AddSingleton(languageServerServiceProvider.GetService<WorkspaceService>())
4856
.AddSingleton(languageServerServiceProvider.GetService<RemoteFileManagerService>())
4957
.AddSingleton<PsesDebugServer>(this)
@@ -85,6 +93,7 @@ public async Task StartAsync(IServiceProvider languageServerServiceProvider)
8593

8694
public void Dispose()
8795
{
96+
_powerShellContextService.IsDebugServerActive = false;
8897
_jsonRpcServer.Dispose();
8998
}
9099

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ private string TrimScriptListingLine(PSObject scriptLineObj, ref int prefixLengt
11911191
/// </summary>
11921192
public event EventHandler<DebuggerStoppedEventArgs> DebuggerStopped;
11931193

1194-
private async void OnDebuggerStopAsync(object sender, DebuggerStopEventArgs e)
1194+
internal async void OnDebuggerStopAsync(object sender, DebuggerStopEventArgs e)
11951195
{
11961196
bool noScriptName = false;
11971197
string localScriptPath = e.InvocationInfo.ScriptName;

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,18 @@ public Task<ConfigurationDoneResponse> Handle(ConfigurationDoneArguments request
7373

7474
if (_debugService.IsDebuggerStopped)
7575
{
76-
// If this is an interactive session and there's a pending breakpoint,
77-
// send that information along to the debugger client
78-
_debugEventHandlerService.TriggerDebuggerStopped(_debugService.CurrentDebuggerStoppedEventArgs);
76+
if (_debugService.CurrentDebuggerStoppedEventArgs != null)
77+
{
78+
// If this is an interactive session and there's a pending breakpoint,
79+
// send that information along to the debugger client
80+
_debugEventHandlerService.TriggerDebuggerStopped(_debugService.CurrentDebuggerStoppedEventArgs);
81+
}
82+
else
83+
{
84+
// If this is an interactive session and there's a pending breakpoint that has not been propagated through
85+
// the debug service, fire the debug service's OnDebuggerStop event.
86+
_debugService.OnDebuggerStopAsync(null, _powerShellContextService.CurrentDebuggerStopEventArgs);
87+
}
7988
}
8089
}
8190

src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ public RunspaceDetails CurrentRunspace
137137
/// </summary>
138138
public string InitialWorkingDirectory { get; private set; }
139139

140+
internal bool IsDebugServerActive { get; set; }
141+
142+
internal DebuggerStopEventArgs CurrentDebuggerStopEventArgs { get; private set; }
143+
140144
#endregion
141145

142146
#region Constructors
@@ -2296,6 +2300,15 @@ private void StartCommandLoopOnRunspaceAvailable()
22962300

22972301
private void OnDebuggerStop(object sender, DebuggerStopEventArgs e)
22982302
{
2303+
// We maintain the current stop event args so that we can use it in the DebugServer to fire the "stopped" event
2304+
// when the DebugServer is fully started.
2305+
CurrentDebuggerStopEventArgs = e;
2306+
2307+
if (!IsDebugServerActive)
2308+
{
2309+
_languageServer.SendNotification("powerShell/startDebugger");
2310+
}
2311+
22992312
if (CurrentRunspace.Context == RunspaceContext.Original)
23002313
{
23012314
StartCommandLoopOnRunspaceAvailable();
@@ -2361,6 +2374,9 @@ private void OnDebuggerStop(object sender, DebuggerStopEventArgs e)
23612374
e.ResumeAction = localDebuggerStoppedTask.GetAwaiter().GetResult();
23622375
this.logger.LogTrace("Received debugger resume action " + e.ResumeAction.ToString());
23632376

2377+
// Since we are no longer at a breakpoint, we set this to null.
2378+
CurrentDebuggerStopEventArgs = null;
2379+
23642380
// Notify listeners that the debugger has resumed
23652381
this.DebuggerResumed?.Invoke(this, e.ResumeAction);
23662382

@@ -2398,6 +2414,9 @@ private void OnDebuggerStop(object sender, DebuggerStopEventArgs e)
23982414
this.PromptNest,
23992415
this.CurrentRunspace.Runspace))
24002416
{
2417+
// Since we are no longer at a breakpoint, we set this to null.
2418+
CurrentDebuggerStopEventArgs = null;
2419+
24012420
if (this.CurrentRunspace.Context == RunspaceContext.DebuggedRunspace)
24022421
{
24032422
// Notify listeners that the debugger has resumed
@@ -2436,8 +2455,7 @@ private void OnBreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
24362455

24372456
private void ConfigureRunspaceCapabilities(RunspaceDetails runspaceDetails)
24382457
{
2439-
// TODO: Bring this back
2440-
//DscBreakpointCapability.CheckForCapability(this.CurrentRunspace, this, this.logger);
2458+
DscBreakpointCapability.CheckForCapability(this.CurrentRunspace, this, this.logger);
24412459
}
24422460

24432461
private void PushRunspace(RunspaceDetails newRunspaceDetails)

0 commit comments

Comments
 (0)