Skip to content

implement powerShell/startDebugger #1049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/PowerShellEditorServices/Server/PsesDebugServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class PsesDebugServer : IDisposable

private IJsonRpcServer _jsonRpcServer;

private PowerShellContextService _powerShellContextService;

public PsesDebugServer(
ILoggerFactory factory,
Stream inputStream,
Expand All @@ -42,8 +44,14 @@ public async Task StartAsync(IServiceProvider languageServerServiceProvider)
options.Reciever = new DapReciever();
options.LoggerFactory = _loggerFactory;
ILogger logger = options.LoggerFactory.CreateLogger("DebugOptionsStartup");

// We need to let the PowerShell Context Service know that we are in a debug session
// so that it doesn't send the powerShell/startDebugger message.
_powerShellContextService = languageServerServiceProvider.GetService<PowerShellContextService>();
_powerShellContextService.IsDebugServerActive = true;

options.Services = new ServiceCollection()
.AddSingleton(languageServerServiceProvider.GetService<PowerShellContextService>())
.AddSingleton(_powerShellContextService)
.AddSingleton(languageServerServiceProvider.GetService<WorkspaceService>())
.AddSingleton(languageServerServiceProvider.GetService<RemoteFileManagerService>())
.AddSingleton<PsesDebugServer>(this)
Expand Down Expand Up @@ -85,6 +93,7 @@ public async Task StartAsync(IServiceProvider languageServerServiceProvider)

public void Dispose()
{
_powerShellContextService.IsDebugServerActive = false;
_jsonRpcServer.Dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ private string TrimScriptListingLine(PSObject scriptLineObj, ref int prefixLengt
/// </summary>
public event EventHandler<DebuggerStoppedEventArgs> DebuggerStopped;

private async void OnDebuggerStopAsync(object sender, DebuggerStopEventArgs e)
internal async void OnDebuggerStopAsync(object sender, DebuggerStopEventArgs e)
{
bool noScriptName = false;
string localScriptPath = e.InvocationInfo.ScriptName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,18 @@ public Task<ConfigurationDoneResponse> Handle(ConfigurationDoneArguments request

if (_debugService.IsDebuggerStopped)
{
// If this is an interactive session and there's a pending breakpoint,
// send that information along to the debugger client
_debugEventHandlerService.TriggerDebuggerStopped(_debugService.CurrentDebuggerStoppedEventArgs);
if (_debugService.CurrentDebuggerStoppedEventArgs != null)
{
// If this is an interactive session and there's a pending breakpoint,
// send that information along to the debugger client
_debugEventHandlerService.TriggerDebuggerStopped(_debugService.CurrentDebuggerStoppedEventArgs);
}
else
{
// If this is an interactive session and there's a pending breakpoint that has not been propagated through
// the debug service, fire the debug service's OnDebuggerStop event.
_debugService.OnDebuggerStopAsync(null, _powerShellContextService.CurrentDebuggerStopEventArgs);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ public RunspaceDetails CurrentRunspace
/// </summary>
public string InitialWorkingDirectory { get; private set; }

internal bool IsDebugServerActive { get; set; }

internal DebuggerStopEventArgs CurrentDebuggerStopEventArgs { get; private set; }

#endregion

#region Constructors
Expand Down Expand Up @@ -2296,6 +2300,15 @@ private void StartCommandLoopOnRunspaceAvailable()

private void OnDebuggerStop(object sender, DebuggerStopEventArgs e)
{
// We maintain the current stop event args so that we can use it in the DebugServer to fire the "stopped" event
// when the DebugServer is fully started.
CurrentDebuggerStopEventArgs = e;

if (!IsDebugServerActive)
{
_languageServer.SendNotification("powerShell/startDebugger");
}

if (CurrentRunspace.Context == RunspaceContext.Original)
{
StartCommandLoopOnRunspaceAvailable();
Expand Down Expand Up @@ -2361,6 +2374,9 @@ private void OnDebuggerStop(object sender, DebuggerStopEventArgs e)
e.ResumeAction = localDebuggerStoppedTask.GetAwaiter().GetResult();
this.logger.LogTrace("Received debugger resume action " + e.ResumeAction.ToString());

// Since we are no longer at a breakpoint, we set this to null.
CurrentDebuggerStopEventArgs = null;

// Notify listeners that the debugger has resumed
this.DebuggerResumed?.Invoke(this, e.ResumeAction);

Expand Down Expand Up @@ -2398,6 +2414,9 @@ private void OnDebuggerStop(object sender, DebuggerStopEventArgs e)
this.PromptNest,
this.CurrentRunspace.Runspace))
{
// Since we are no longer at a breakpoint, we set this to null.
CurrentDebuggerStopEventArgs = null;

if (this.CurrentRunspace.Context == RunspaceContext.DebuggedRunspace)
{
// Notify listeners that the debugger has resumed
Expand Down Expand Up @@ -2436,8 +2455,7 @@ private void OnBreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)

private void ConfigureRunspaceCapabilities(RunspaceDetails runspaceDetails)
{
// TODO: Bring this back
//DscBreakpointCapability.CheckForCapability(this.CurrentRunspace, this, this.logger);
DscBreakpointCapability.CheckForCapability(this.CurrentRunspace, this, this.logger);
}

private void PushRunspace(RunspaceDetails newRunspaceDetails)
Expand Down