Skip to content

Commit 04e942e

Browse files
committed
Set AllThreadsStopped appropriately
1 parent e29979c commit 04e942e

File tree

5 files changed

+30
-36
lines changed

5 files changed

+30
-36
lines changed

src/PowerShellEditorServices/Server/PsesDebugServer.cs

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public async Task StartAsync()
137137
public void Dispose()
138138
{
139139
_powerShellContextService.IsDebugServerActive = false;
140+
// TODO: If the debugger has stopped, should we clear the breakpoints?
140141
_debugAdapterServer.Dispose();
141142
_inputStream.Dispose();
142143
_outputStream.Dispose();

src/PowerShellEditorServices/Services/DebugAdapter/BreakpointService.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ public async Task<IEnumerable<BreakpointDetails>> SetBreakpointsAsync(string esc
135135
IEnumerable<Breakpoint> setBreakpoints =
136136
await _powerShellContextService.ExecuteCommandAsync<Breakpoint>(psCommand).ConfigureAwait(false);
137137
configuredBreakpoints.AddRange(
138-
setBreakpoints.Select(BreakpointDetails.Create));
138+
setBreakpoints.Select((breakpoint) => BreakpointDetails.Create(breakpoint))
139+
);
139140
}
140141

141142
return configuredBreakpoints;

src/PowerShellEditorServices/Services/DebugAdapter/DebugEventHandlerService.cs

+21-32
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ e.OriginalEvent.Breakpoints[0] is CommandBreakpoint
8181
new StoppedEvent
8282
{
8383
ThreadId = 1,
84+
AllThreadsStopped = true,
8485
Reason = debuggerStoppedReason
8586
});
8687
}
@@ -117,59 +118,47 @@ private void PowerShellContext_DebuggerResumed(object sender, DebuggerResumeActi
117118
_debugAdapterServer.SendNotification(EventNames.Continued,
118119
new ContinuedEvent
119120
{
120-
AllThreadsContinued = true,
121-
ThreadId = 1
121+
ThreadId = 1,
122+
AllThreadsContinued = true
122123
});
123124
}
124125

125126
private void DebugService_BreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
126127
{
127-
string reason = "changed";
128-
128+
// Don't send breakpoint update notifications when setting
129+
// breakpoints on behalf of the client.
129130
if (_debugStateService.IsSetBreakpointInProgress)
130131
{
131-
// Don't send breakpoint update notifications when setting
132-
// breakpoints on behalf of the client.
133132
return;
134133
}
135134

136-
switch (e.UpdateType)
137-
{
138-
case BreakpointUpdateType.Set:
139-
reason = "new";
140-
break;
141-
142-
case BreakpointUpdateType.Removed:
143-
reason = "removed";
144-
break;
145-
}
146-
147-
var breakpoint = new OmniSharp.Extensions.DebugAdapter.Protocol.Models.Breakpoint
148-
{
149-
Verified = e.UpdateType != BreakpointUpdateType.Disabled
150-
};
151-
152135
if (e.Breakpoint is LineBreakpoint)
153136
{
154-
breakpoint = LspDebugUtils.CreateBreakpoint(BreakpointDetails.Create(e.Breakpoint));
137+
var breakpoint = LspDebugUtils.CreateBreakpoint(
138+
BreakpointDetails.Create(e.Breakpoint, e.UpdateType)
139+
);
140+
141+
string reason = (e.UpdateType) switch {
142+
BreakpointUpdateType.Set => "new",
143+
BreakpointUpdateType.Removed => "removed",
144+
BreakpointUpdateType.Enabled => "changed",
145+
BreakpointUpdateType.Disabled => "changed",
146+
_ => "unknown"
147+
};
148+
149+
_debugAdapterServer.SendNotification(
150+
EventNames.Breakpoint,
151+
new BreakpointEvent { Reason = reason, Breakpoint = breakpoint }
152+
);
155153
}
156154
else if (e.Breakpoint is CommandBreakpoint)
157155
{
158156
_logger.LogTrace("Function breakpoint updated event is not supported yet");
159-
return;
160157
}
161158
else
162159
{
163160
_logger.LogError($"Unrecognized breakpoint type {e.Breakpoint.GetType().FullName}");
164-
return;
165161
}
166-
167-
_debugAdapterServer.SendNotification(EventNames.Breakpoint,
168-
new BreakpointEvent
169-
{
170-
Reason = reason,
171-
Breakpoint = breakpoint
172-
});
173162
}
174163

175164
#endregion

src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointDetails.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ internal static BreakpointDetails Create(
7777
/// PowerShell Breakpoint object.
7878
/// </summary>
7979
/// <param name="breakpoint">The Breakpoint instance from which details will be taken.</param>
80+
/// <param name="updateType">The BreakpointUpdateType to determine if the breakpoint is verified.</param>
8081
/// <returns>A new instance of the BreakpointDetails class.</returns>
81-
internal static BreakpointDetails Create(Breakpoint breakpoint)
82+
internal static BreakpointDetails Create(
83+
Breakpoint breakpoint,
84+
BreakpointUpdateType updateType = BreakpointUpdateType.Set)
8285
{
8386
Validate.IsNotNull("breakpoint", breakpoint);
8487

@@ -91,7 +94,7 @@ internal static BreakpointDetails Create(Breakpoint breakpoint)
9194
var breakpointDetails = new BreakpointDetails
9295
{
9396
Id = breakpoint.Id,
94-
Verified = true,
97+
Verified = updateType != BreakpointUpdateType.Disabled,
9598
Source = lineBreakpoint.Script,
9699
LineNumber = lineBreakpoint.Line,
97100
ColumnNumber = lineBreakpoint.Column,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public Task<ThreadsResponse> Handle(ThreadsArguments request, CancellationToken
2020
{
2121
// TODO: OmniSharp supports multithreaded debugging (where
2222
// multiple threads can be debugged at once), but we don't. This
23-
// means we always need to set AllThreadsStoppped and
23+
// means we always need to set AllThreadsStopped and
2424
// AllThreadsContinued in our events. But if we one day support
2525
// multithreaded debugging, we'd need a way to associate
2626
// debugged runspaces with .NET threads in a consistent way.

0 commit comments

Comments
 (0)