Skip to content

Commit

Permalink
service/dap: Adds launch request support for program args (#2040)
Browse files Browse the repository at this point in the history
* Adds launch request support for program args

* Combine types of function parameters

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
  • Loading branch information
polinasok and polinasok authored May 11, 2020
1 parent 71a460f commit f92afb9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
30 changes: 25 additions & 5 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,33 @@ func (s *Server) onLaunchRequest(request *dap.LaunchRequest) {
stop, ok := request.Arguments["stopOnEntry"]
s.stopOnEntry = ok && stop == true

// TODO(polina): support target args
s.config.ProcessArgs = []string{program}
var targetArgs []string
args, ok := request.Arguments["args"]
if ok {
argsParsed, ok := args.([]interface{})
if !ok {
s.sendErrorResponse(request.Request,
FailedToContinue, "Failed to launch",
fmt.Sprintf("'args' attribute '%v' in debug configuration is not an array.", args))
return
}
for _, arg := range argsParsed {
argParsed, ok := arg.(string)
if !ok {
s.sendErrorResponse(request.Request,
FailedToContinue, "Failed to launch",
fmt.Sprintf("value '%v' in 'args' attribute in debug configuration is not a string.", arg))
return
}
targetArgs = append(targetArgs, argParsed)
}
}

s.config.ProcessArgs = append([]string{program}, targetArgs...)
s.config.Debugger.WorkingDir = filepath.Dir(program)

config := s.config.Debugger
var err error
if s.debugger, err = debugger.New(&config, s.config.ProcessArgs); err != nil {
if s.debugger, err = debugger.New(&s.config.Debugger, s.config.ProcessArgs); err != nil {
s.sendErrorResponse(request.Request,
FailedToContinue, "Failed to launch", err.Error())
return
Expand Down Expand Up @@ -686,7 +706,7 @@ func (s *Server) onCancelRequest(request *dap.CancelRequest) {
s.sendNotYetImplementedErrorResponse(request.Request)
}

func (s *Server) sendErrorResponse(request dap.Request, id int, summary string, details string) {
func (s *Server) sendErrorResponse(request dap.Request, id int, summary, details string) {
er := &dap.ErrorResponse{}
er.Type = "response"
er.Command = request.Command
Expand Down
22 changes: 22 additions & 0 deletions service/dap/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ func TestLaunchTestRequest(t *testing.T) {
})
}

func TestLaunchRequestWithArgs(t *testing.T) {
runTest(t, "testargs", func(client *daptest.Client, fixture protest.Fixture) {
runDebugSession(t, client, func() {
client.LaunchRequestWithArgs(map[string]interface{}{
"mode": "exec", "program": fixture.Path,
"args": []string{"test", "pass flag"}})
})
})
}

func TestUnupportedCommandResponses(t *testing.T) {
var got *dap.ErrorResponse
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
Expand Down Expand Up @@ -564,6 +574,18 @@ func TestBadLaunchRequests(t *testing.T) {
expectFailedToLaunchWithMessage(client.ExpectErrorResponse(t),
"Failed to launch: Unsupported 'mode' value %!q(float64=12345) in debug configuration.")

client.LaunchRequestWithArgs(map[string]interface{}{"mode": "exec", "program": fixture.Path, "args": nil})
expectFailedToLaunchWithMessage(client.ExpectErrorResponse(t),
"Failed to launch: 'args' attribute '<nil>' in debug configuration is not an array.")

client.LaunchRequestWithArgs(map[string]interface{}{"mode": "exec", "program": fixture.Path, "args": 12345})
expectFailedToLaunchWithMessage(client.ExpectErrorResponse(t),
"Failed to launch: 'args' attribute '12345' in debug configuration is not an array.")

client.LaunchRequestWithArgs(map[string]interface{}{"mode": "exec", "program": fixture.Path, "args": []int{1, 2}})
expectFailedToLaunchWithMessage(client.ExpectErrorResponse(t),
"Failed to launch: value '1' in 'args' attribute in debug configuration is not a string.")

// Skip detailed message checks for potentially different OS-specific errors.
client.LaunchRequest("exec", fixture.Path+"_does_not_exist", stopOnEntry)
expectFailedToLaunch(client.ExpectErrorResponse(t))
Expand Down

0 comments on commit f92afb9

Please sign in to comment.