Skip to content

Commit 776b86f

Browse files
authored
service/dap: send continued event before step response (#2594)
* service/dap: send continued event before step response Send the continued event before the step response to make sure that there is no time where the client believes that only a single thread is running. Updates golang/vscode-go#1617 * move to helper
1 parent 38aaf27 commit 776b86f

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

service/dap/daptest/gen/main.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dap/daptest/resp.go

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/dap/server.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,24 +1510,37 @@ func (s *Server) onAttachRequest(request *dap.AttachRequest) {
15101510
// onNextRequest handles 'next' request.
15111511
// This is a mandatory request to support.
15121512
func (s *Server) onNextRequest(request *dap.NextRequest, asyncSetupDone chan struct{}) {
1513-
s.send(&dap.NextResponse{Response: *newResponse(request.Request)})
1513+
s.sendStepResponse(request.Arguments.ThreadId, &dap.NextResponse{Response: *newResponse(request.Request)})
15141514
s.doStepCommand(api.Next, request.Arguments.ThreadId, asyncSetupDone)
15151515
}
15161516

15171517
// onStepInRequest handles 'stepIn' request
15181518
// This is a mandatory request to support.
15191519
func (s *Server) onStepInRequest(request *dap.StepInRequest, asyncSetupDone chan struct{}) {
1520-
s.send(&dap.StepInResponse{Response: *newResponse(request.Request)})
1520+
s.sendStepResponse(request.Arguments.ThreadId, &dap.StepInResponse{Response: *newResponse(request.Request)})
15211521
s.doStepCommand(api.Step, request.Arguments.ThreadId, asyncSetupDone)
15221522
}
15231523

15241524
// onStepOutRequest handles 'stepOut' request
15251525
// This is a mandatory request to support.
15261526
func (s *Server) onStepOutRequest(request *dap.StepOutRequest, asyncSetupDone chan struct{}) {
1527-
s.send(&dap.StepOutResponse{Response: *newResponse(request.Request)})
1527+
s.sendStepResponse(request.Arguments.ThreadId, &dap.StepOutResponse{Response: *newResponse(request.Request)})
15281528
s.doStepCommand(api.StepOut, request.Arguments.ThreadId, asyncSetupDone)
15291529
}
15301530

1531+
func (s *Server) sendStepResponse(threadId int, message dap.Message) {
1532+
// All of the threads will be continued by this request, so we need to send
1533+
// a continued event so the UI can properly reflect the current state.
1534+
s.send(&dap.ContinuedEvent{
1535+
Event: *newEvent("continued"),
1536+
Body: dap.ContinuedEventBody{
1537+
ThreadId: threadId,
1538+
AllThreadsContinued: true,
1539+
},
1540+
})
1541+
s.send(message)
1542+
}
1543+
15311544
func stoppedGoroutineID(state *api.DebuggerState) (id int) {
15321545
if state.SelectedGoroutine != nil {
15331546
id = state.SelectedGoroutine.ID
@@ -1544,15 +1557,6 @@ func stoppedGoroutineID(state *api.DebuggerState) (id int) {
15441557
// due to an error, so the server is ready to receive new requests.
15451558
func (s *Server) doStepCommand(command string, threadId int, asyncSetupDone chan struct{}) {
15461559
defer s.asyncCommandDone(asyncSetupDone)
1547-
// All of the threads will be continued by this request, so we need to send
1548-
// a continued event so the UI can properly reflect the current state.
1549-
s.send(&dap.ContinuedEvent{
1550-
Event: *newEvent("continued"),
1551-
Body: dap.ContinuedEventBody{
1552-
ThreadId: threadId,
1553-
AllThreadsContinued: true,
1554-
},
1555-
})
15561560
_, err := s.debugger.Command(&api.DebuggerCommand{Name: api.SwitchGoroutine, GoroutineID: threadId}, nil)
15571561
if err != nil {
15581562
s.log.Errorf("Error switching goroutines while stepping: %v", err)

0 commit comments

Comments
 (0)