Skip to content

Commit

Permalink
service/dap: send continued event before step response
Browse files Browse the repository at this point in the history
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
  • Loading branch information
suzmue committed Jul 16, 2021
1 parent f86ed67 commit c534554
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
14 changes: 7 additions & 7 deletions service/dap/daptest/gen/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions service/dap/daptest/resp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 27 additions & 9 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1458,20 +1458,47 @@ func (s *Server) onAttachRequest(request *dap.AttachRequest) {
// onNextRequest handles 'next' request.
// This is a mandatory request to support.
func (s *Server) onNextRequest(request *dap.NextRequest, asyncSetupDone chan struct{}) {
// All of the threads will be continued by this request, so we need to send
// a continued event so the UI can properly reflect the current state.
s.send(&dap.ContinuedEvent{
Event: *newEvent("continued"),
Body: dap.ContinuedEventBody{
ThreadId: request.Arguments.ThreadId,
AllThreadsContinued: true,
},
})
s.send(&dap.NextResponse{Response: *newResponse(request.Request)})
s.doStepCommand(api.Next, request.Arguments.ThreadId, asyncSetupDone)
}

// onStepInRequest handles 'stepIn' request
// This is a mandatory request to support.
func (s *Server) onStepInRequest(request *dap.StepInRequest, asyncSetupDone chan struct{}) {
// All of the threads will be continued by this request, so we need to send
// a continued event so the UI can properly reflect the current state.
s.send(&dap.ContinuedEvent{
Event: *newEvent("continued"),
Body: dap.ContinuedEventBody{
ThreadId: request.Arguments.ThreadId,
AllThreadsContinued: true,
},
})
s.send(&dap.StepInResponse{Response: *newResponse(request.Request)})
s.doStepCommand(api.Step, request.Arguments.ThreadId, asyncSetupDone)
}

// onStepOutRequest handles 'stepOut' request
// This is a mandatory request to support.
func (s *Server) onStepOutRequest(request *dap.StepOutRequest, asyncSetupDone chan struct{}) {
// All of the threads will be continued by this request, so we need to send
// a continued event so the UI can properly reflect the current state.
s.send(&dap.ContinuedEvent{
Event: *newEvent("continued"),
Body: dap.ContinuedEventBody{
ThreadId: request.Arguments.ThreadId,
AllThreadsContinued: true,
},
})
s.send(&dap.StepOutResponse{Response: *newResponse(request.Request)})
s.doStepCommand(api.StepOut, request.Arguments.ThreadId, asyncSetupDone)
}
Expand All @@ -1492,15 +1519,6 @@ func stoppedGoroutineID(state *api.DebuggerState) (id int) {
// due to an error, so the server is ready to receive new requests.
func (s *Server) doStepCommand(command string, threadId int, asyncSetupDone chan struct{}) {
defer s.asyncCommandDone(asyncSetupDone)
// All of the threads will be continued by this request, so we need to send
// a continued event so the UI can properly reflect the current state.
s.send(&dap.ContinuedEvent{
Event: *newEvent("continued"),
Body: dap.ContinuedEventBody{
ThreadId: threadId,
AllThreadsContinued: true,
},
})
_, err := s.debugger.Command(&api.DebuggerCommand{Name: api.SwitchGoroutine, GoroutineID: threadId}, nil)
if err != nil {
s.log.Errorf("Error switching goroutines while stepping: %v", err)
Expand Down

0 comments on commit c534554

Please sign in to comment.