Skip to content

Breakpoints hit when debugger isn't active now notify editor #455

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 1 commit into from
May 17, 2017
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;

namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer
{
public class StartDebuggerEvent
{
public static readonly
NotificationType<object, object> Type =
NotificationType<object, object>.Create("powerShell/startDebugger");
}
}
21 changes: 18 additions & 3 deletions src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ private async Task OnExecutionCompleted(Task executeTask)
}
}

this.editorSession.DebugService.IsClientAttached = false;

if (this.disconnectRequestContext != null)
{
// Respond to the disconnect request and stop the server
Expand Down Expand Up @@ -207,6 +209,8 @@ protected async Task HandleConfigurationDoneRequest(
object args,
RequestContext<object> requestContext)
{
this.editorSession.DebugService.IsClientAttached = true;

if (!string.IsNullOrEmpty(this.scriptToLaunch))
{
if (this.editorSession.PowerShellContext.SessionState == PowerShellContextState.Ready)
Expand All @@ -225,6 +229,16 @@ protected async Task HandleConfigurationDoneRequest(
}

await requestContext.SendResult(null);

if (this.isInteractiveDebugSession &&
this.editorSession.DebugService.IsDebuggerStopped)
{
// If this is an interactive session and there's a pending breakpoint,
// send that information along to the debugger client
this.DebugService_DebuggerStopped(
this,
this.editorSession.DebugService.CurrentDebuggerStoppedEventArgs);
}
}

protected async Task HandleLaunchRequest(
Expand Down Expand Up @@ -270,8 +284,8 @@ protected async Task HandleLaunchRequest(
#endif
}

// TODO: What's the right approach here?
if (this.editorSession.PowerShellContext.CurrentRunspace.Location == RunspaceLocation.Local)
if (this.editorSession.PowerShellContext.CurrentRunspace.Location == RunspaceLocation.Local &&
!this.editorSession.DebugService.IsDebuggerStopped)
{
await editorSession.PowerShellContext.SetWorkingDirectory(workingDir);
Logger.Write(LogLevel.Verbose, "Working dir set to: " + workingDir);
Expand All @@ -294,7 +308,8 @@ protected async Task HandleLaunchRequest(

// If the current session is remote, map the script path to the remote
// machine if necessary
if (this.editorSession.PowerShellContext.CurrentRunspace.Location == RunspaceLocation.Remote)
if (this.scriptToLaunch != null &&
this.editorSession.PowerShellContext.CurrentRunspace.Location == RunspaceLocation.Remote)
{
this.scriptToLaunch =
this.editorSession.RemoteFileManager.GetMappedPath(
Expand Down
11 changes: 11 additions & 0 deletions src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using Microsoft.PowerShell.EditorServices.Debugging;
using Microsoft.PowerShell.EditorServices.Extensions;
using Microsoft.PowerShell.EditorServices.Protocol.LanguageServer;
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
Expand Down Expand Up @@ -82,6 +83,7 @@ public LanguageServer(
this);

this.editorSession.StartDebugService(this.editorOperations);
this.editorSession.DebugService.DebuggerStopped += DebugService_DebuggerStopped;

if (enableConsoleRepl)
{
Expand Down Expand Up @@ -1193,6 +1195,15 @@ await this.SendEvent(
});
}

private async void DebugService_DebuggerStopped(object sender, DebuggerStoppedEventArgs e)
{
if (!this.editorSession.DebugService.IsClientAttached)
{
await this.SendEvent(
StartDebuggerEvent.Type,
new StartDebuggerEvent());
}
}

#endregion

Expand Down
40 changes: 36 additions & 4 deletions src/PowerShellEditorServices/Debugging/DebugService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ public class DebugService

#endregion

#region Properties

/// <summary>
/// Gets or sets a boolean that indicates whether a debugger client is
/// currently attached to the debugger.
/// </summary>
public bool IsClientAttached { get; set; }

/// <summary>
/// Gets a boolean that indicates whether the debugger is currently
/// stopped at a breakpoint.
/// </summary>
public bool IsDebuggerStopped => this.powerShellContext.IsDebuggerStopped;

/// <summary>
/// Gets the current DebuggerStoppedEventArgs when the debugger
/// is stopped.
/// </summary>
public DebuggerStoppedEventArgs CurrentDebuggerStoppedEventArgs { get; private set; }

#endregion

#region Constructors

/// <summary>
Expand Down Expand Up @@ -80,6 +102,8 @@ public DebugService(

this.powerShellContext = powerShellContext;
this.powerShellContext.DebuggerStop += this.OnDebuggerStop;
this.powerShellContext.DebuggerResumed += this.OnDebuggerResumed;

this.powerShellContext.BreakpointUpdated += this.OnBreakpointUpdated;

this.remoteFileManager = remoteFileManager;
Expand Down Expand Up @@ -1126,13 +1150,21 @@ await this.remoteFileManager.FetchRemoteFile(
}
}

// Notify the host that the debugger is stopped
this.DebuggerStopped?.Invoke(
sender,
this.CurrentDebuggerStoppedEventArgs =
new DebuggerStoppedEventArgs(
e,
this.powerShellContext.CurrentRunspace,
localScriptPath));
localScriptPath);

// Notify the host that the debugger is stopped
this.DebuggerStopped?.Invoke(
sender,
this.CurrentDebuggerStoppedEventArgs);
}

private void OnDebuggerResumed(object sender, DebuggerResumeAction e)
{
this.CurrentDebuggerStoppedEventArgs = null;
}

/// <summary>
Expand Down