Skip to content

Commit

Permalink
Update breakpoint status change notifications to DAP way
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneySprings committed Feb 17, 2024
1 parent 53faad6 commit a2032bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/DotNet.Meteor.Debug/DebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class DebugSession : Session {
session.TargetExited += TargetExited;
session.TargetThreadStarted += TargetThreadStarted;
session.TargetThreadStopped += TargetThreadStopped;

session.Breakpoints.BreakpointStatusChanged += BreakpointStatusChanged;
}

protected override MonoClient.ICustomLogger GetLogger() => MonoClient.DebuggerLoggingService.CustomLogger;
Expand Down Expand Up @@ -196,9 +198,9 @@ public class DebugSession : Session {
breakpoint.TraceExpression = $"[LogPoint]: {breakpointInfo.LogMessage}";
}

var verified = breakpoint.WaitForBound(session);
breakpoints.Add(new DebugProtocol.Breakpoint() {
Verified = verified,
Id = breakpoint.GetHashCode(),
Verified = false, // updated by event
Line = breakpoint.Line,
Column = breakpoint.Column
});
Expand Down Expand Up @@ -502,6 +504,9 @@ public class DebugSession : Session {
GetLogger().LogError($"[Handled] {ex.Message}", ex);
return true;
}
private void BreakpointStatusChanged(object sender, MonoClient.BreakpointEventArgs e) {
Protocol.SendEvent(new BreakpointEvent(BreakpointEvent.ReasonValue.Changed, e.Breakpoint.ToBreakpoint(session)));
}
private void OnSessionLog(bool isError, string message) {
if (isError) GetLogger().LogError($"[Error] {message.Trim()}", null);
else GetLogger().LogMessage($"[Info] {message.Trim()}");
Expand Down
7 changes: 0 additions & 7 deletions src/DotNet.Meteor.Debug/Extensions/MonoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,4 @@ public static class MonoExtensions {
options.UseExternalTypeResolver = useExternalTypeResolver;
return frame.GetExpressionValue(expression, options);
}
public static bool WaitForBound(this BreakEvent breakEvent, SoftDebuggerSession session, int millisecondsTimeout = 150) {
return Task.Run(async() => {
while (breakEvent.GetStatus(session) == BreakEventStatus.NotBound)
await Task.Delay(millisecondsTimeout/3);
return breakEvent.GetStatus(session) == BreakEventStatus.Bound;
}).Wait(millisecondsTimeout);
}
}
14 changes: 12 additions & 2 deletions src/DotNet.Meteor.Debug/Extensions/ServerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
using System.Text.Json.Serialization.Metadata;
using Newtonsoft.Json.Linq;
using NewtonConverter = Newtonsoft.Json.JsonConvert;
using DebugProtocol = Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages;
using DebugProtocol = Microsoft.VisualStudio.Shared.VSCodeDebugProtocol.Messages;
using System.IO;
using Microsoft.VisualStudio.Shared.VSCodeDebugProtocol;
using DotNet.Meteor.Shared;
using System.Collections.Generic;
using Mono.Debugging.Soft;

namespace DotNet.Meteor.Debug.Extensions;

Expand Down Expand Up @@ -85,4 +85,14 @@ public static class ServerExtensions {

return DebugProtocol.CompletionItemType.Text;
}

public static DebugProtocol.Breakpoint ToBreakpoint(this Breakpoint breakpoint, SoftDebuggerSession session) {
return new DebugProtocol.Breakpoint() {
Id = breakpoint.GetHashCode(),
Verified = breakpoint.GetStatus(session) == BreakEventStatus.Bound,
Message = breakpoint.GetStatusMessage(session),
Line = breakpoint.Line,
Column = breakpoint.Column,
};
}
}

0 comments on commit a2032bd

Please sign in to comment.