Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
SeeminglyScience committed Sep 20, 2023
1 parent d6971a9 commit 8c10d8a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,50 +141,60 @@ public bool IsMutatingBreakpoints

public async Task UpdatedByServerAsync(BreakpointUpdatedEventArgs eventArgs)
{
if (!_map.ByPwshId.TryGetValue(eventArgs.Breakpoint.Id, out SyncedBreakpoint existing))
if (_map.ByPwshId.TryGetValue(eventArgs.Breakpoint.Id, out SyncedBreakpoint existing))
{
// If we haven't told the client about the breakpoint yet then we can just ignore.
if (eventArgs.UpdateType is BreakpointUpdateType.Removed)
{
return;
}

existing = CreateFromServerBreakpoint(eventArgs.Breakpoint);
string? id = await SendToClientAsync(existing.Client, BreakpointUpdateType.Set)
.ConfigureAwait(false);

existing.Client.Id = id!;
RegisterBreakpoint(existing);
await ProcessExistingBreakpoint(eventArgs, existing).ConfigureAwait(false);
return;
}

// If we haven't told the client about the breakpoint yet then we can just ignore.
if (eventArgs.UpdateType is BreakpointUpdateType.Removed)
{
UnregisterBreakpoint(existing);
await SendToClientAsync(existing.Client, BreakpointUpdateType.Removed).ConfigureAwait(false);
return;
}

if (eventArgs.UpdateType is BreakpointUpdateType.Enabled or BreakpointUpdateType.Disabled)
SyncedBreakpoint newBreakpoint = CreateFromServerBreakpoint(eventArgs.Breakpoint);
string? id = await SendToClientAsync(newBreakpoint.Client, BreakpointUpdateType.Set)
.ConfigureAwait(false);

if (id is null)
{
LogBreakpointError(newBreakpoint, "Did not receive a breakpoint ID from the client.");
}

newBreakpoint.Client.Id = id;
RegisterBreakpoint(newBreakpoint);

async Task ProcessExistingBreakpoint(BreakpointUpdatedEventArgs eventArgs, SyncedBreakpoint existing)
{
await SendToClientAsync(existing.Client, eventArgs.UpdateType).ConfigureAwait(false);
bool isActive = eventArgs.UpdateType is BreakpointUpdateType.Enabled;
SyncedBreakpoint newBreakpoint = existing with
if (eventArgs.UpdateType is BreakpointUpdateType.Removed)
{
UnregisterBreakpoint(existing);
await SendToClientAsync(existing.Client, BreakpointUpdateType.Removed).ConfigureAwait(false);
return;
}

if (eventArgs.UpdateType is BreakpointUpdateType.Enabled or BreakpointUpdateType.Disabled)
{
Client = existing.Client with
await SendToClientAsync(existing.Client, eventArgs.UpdateType).ConfigureAwait(false);
bool isActive = eventArgs.UpdateType is BreakpointUpdateType.Enabled;
SyncedBreakpoint newBreakpoint = existing with
{
Enabled = isActive,
},
};
Client = existing.Client with
{
Enabled = isActive,
},
};

UnregisterBreakpoint(existing);
RegisterBreakpoint(newBreakpoint);
return;
}
UnregisterBreakpoint(existing);
RegisterBreakpoint(newBreakpoint);
return;
}

LogBreakpointError(
existing,
"Somehow we're syncing a new breakpoint that we've already sync'd. That's not supposed to happen.");
LogBreakpointError(
existing,
"Somehow we're syncing a new breakpoint that we've already sync'd. That's not supposed to happen.");
}
}

public IReadOnlyList<SyncedBreakpoint> GetSyncedBreakpoints() => _map.ByGuid.Values.ToArray();
Expand Down Expand Up @@ -521,7 +531,6 @@ private static SyncedBreakpoint CreateFromServerBreakpoint(Breakpoint serverBrea
else if (serverBreakpoint is LineBreakpoint lbp)
{
location = new ClientLocation(
// TODO: fix the translation of this
lbp.Script,
new Range(
lbp.Line - 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.IO;
using System.Management.Automation;
using System.Management.Automation.Remoting;
using System.Management.Automation.Runspaces;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -241,12 +240,6 @@ public async Task<AttachResponse> Handle(PsesAttachRequestArguments request, Can

private async Task<AttachResponse> HandleImpl(PsesAttachRequestArguments request, CancellationToken cancellationToken)
{
cancellationToken.Register(() =>
{
if (Runspace.DefaultRunspace != null)
{
}
});
// The debugger has officially started. We use this to later check if we should stop it.
((PsesInternalHost)_executionService).DebugContext.IsActive = true;

Expand Down

0 comments on commit 8c10d8a

Please sign in to comment.