Skip to content

Commit 8c10d8a

Browse files
Address PR feedback
1 parent d6971a9 commit 8c10d8a

File tree

2 files changed

+40
-38
lines changed

2 files changed

+40
-38
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/BreakpointSyncService.cs

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -141,50 +141,60 @@ public bool IsMutatingBreakpoints
141141

142142
public async Task UpdatedByServerAsync(BreakpointUpdatedEventArgs eventArgs)
143143
{
144-
if (!_map.ByPwshId.TryGetValue(eventArgs.Breakpoint.Id, out SyncedBreakpoint existing))
144+
if (_map.ByPwshId.TryGetValue(eventArgs.Breakpoint.Id, out SyncedBreakpoint existing))
145145
{
146-
// If we haven't told the client about the breakpoint yet then we can just ignore.
147-
if (eventArgs.UpdateType is BreakpointUpdateType.Removed)
148-
{
149-
return;
150-
}
151-
152-
existing = CreateFromServerBreakpoint(eventArgs.Breakpoint);
153-
string? id = await SendToClientAsync(existing.Client, BreakpointUpdateType.Set)
154-
.ConfigureAwait(false);
155-
156-
existing.Client.Id = id!;
157-
RegisterBreakpoint(existing);
146+
await ProcessExistingBreakpoint(eventArgs, existing).ConfigureAwait(false);
158147
return;
159148
}
160149

150+
// If we haven't told the client about the breakpoint yet then we can just ignore.
161151
if (eventArgs.UpdateType is BreakpointUpdateType.Removed)
162152
{
163-
UnregisterBreakpoint(existing);
164-
await SendToClientAsync(existing.Client, BreakpointUpdateType.Removed).ConfigureAwait(false);
165153
return;
166154
}
167155

168-
if (eventArgs.UpdateType is BreakpointUpdateType.Enabled or BreakpointUpdateType.Disabled)
156+
SyncedBreakpoint newBreakpoint = CreateFromServerBreakpoint(eventArgs.Breakpoint);
157+
string? id = await SendToClientAsync(newBreakpoint.Client, BreakpointUpdateType.Set)
158+
.ConfigureAwait(false);
159+
160+
if (id is null)
161+
{
162+
LogBreakpointError(newBreakpoint, "Did not receive a breakpoint ID from the client.");
163+
}
164+
165+
newBreakpoint.Client.Id = id;
166+
RegisterBreakpoint(newBreakpoint);
167+
168+
async Task ProcessExistingBreakpoint(BreakpointUpdatedEventArgs eventArgs, SyncedBreakpoint existing)
169169
{
170-
await SendToClientAsync(existing.Client, eventArgs.UpdateType).ConfigureAwait(false);
171-
bool isActive = eventArgs.UpdateType is BreakpointUpdateType.Enabled;
172-
SyncedBreakpoint newBreakpoint = existing with
170+
if (eventArgs.UpdateType is BreakpointUpdateType.Removed)
171+
{
172+
UnregisterBreakpoint(existing);
173+
await SendToClientAsync(existing.Client, BreakpointUpdateType.Removed).ConfigureAwait(false);
174+
return;
175+
}
176+
177+
if (eventArgs.UpdateType is BreakpointUpdateType.Enabled or BreakpointUpdateType.Disabled)
173178
{
174-
Client = existing.Client with
179+
await SendToClientAsync(existing.Client, eventArgs.UpdateType).ConfigureAwait(false);
180+
bool isActive = eventArgs.UpdateType is BreakpointUpdateType.Enabled;
181+
SyncedBreakpoint newBreakpoint = existing with
175182
{
176-
Enabled = isActive,
177-
},
178-
};
183+
Client = existing.Client with
184+
{
185+
Enabled = isActive,
186+
},
187+
};
179188

180-
UnregisterBreakpoint(existing);
181-
RegisterBreakpoint(newBreakpoint);
182-
return;
183-
}
189+
UnregisterBreakpoint(existing);
190+
RegisterBreakpoint(newBreakpoint);
191+
return;
192+
}
184193

185-
LogBreakpointError(
186-
existing,
187-
"Somehow we're syncing a new breakpoint that we've already sync'd. That's not supposed to happen.");
194+
LogBreakpointError(
195+
existing,
196+
"Somehow we're syncing a new breakpoint that we've already sync'd. That's not supposed to happen.");
197+
}
188198
}
189199

190200
public IReadOnlyList<SyncedBreakpoint> GetSyncedBreakpoints() => _map.ByGuid.Values.ToArray();
@@ -521,7 +531,6 @@ private static SyncedBreakpoint CreateFromServerBreakpoint(Breakpoint serverBrea
521531
else if (serverBreakpoint is LineBreakpoint lbp)
522532
{
523533
location = new ClientLocation(
524-
// TODO: fix the translation of this
525534
lbp.Script,
526535
new Range(
527536
lbp.Line - 1,

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.IO;
77
using System.Management.Automation;
88
using System.Management.Automation.Remoting;
9-
using System.Management.Automation.Runspaces;
109
using System.Threading;
1110
using System.Threading.Tasks;
1211
using Microsoft.Extensions.Logging;
@@ -241,12 +240,6 @@ public async Task<AttachResponse> Handle(PsesAttachRequestArguments request, Can
241240

242241
private async Task<AttachResponse> HandleImpl(PsesAttachRequestArguments request, CancellationToken cancellationToken)
243242
{
244-
cancellationToken.Register(() =>
245-
{
246-
if (Runspace.DefaultRunspace != null)
247-
{
248-
}
249-
});
250243
// The debugger has officially started. We use this to later check if we should stop it.
251244
((PsesInternalHost)_executionService).DebugContext.IsActive = true;
252245

0 commit comments

Comments
 (0)