service/dap: Adds launch request support for program args (#2040)
* Adds launch request support for program args * Combine types of function parameters Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
This commit is contained in:
parent
71a460fc0f
commit
f92afb9c17
@ -434,13 +434,33 @@ func (s *Server) onLaunchRequest(request *dap.LaunchRequest) {
|
|||||||
stop, ok := request.Arguments["stopOnEntry"]
|
stop, ok := request.Arguments["stopOnEntry"]
|
||||||
s.stopOnEntry = ok && stop == true
|
s.stopOnEntry = ok && stop == true
|
||||||
|
|
||||||
// TODO(polina): support target args
|
var targetArgs []string
|
||||||
s.config.ProcessArgs = []string{program}
|
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)
|
s.config.Debugger.WorkingDir = filepath.Dir(program)
|
||||||
|
|
||||||
config := s.config.Debugger
|
|
||||||
var err error
|
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,
|
s.sendErrorResponse(request.Request,
|
||||||
FailedToContinue, "Failed to launch", err.Error())
|
FailedToContinue, "Failed to launch", err.Error())
|
||||||
return
|
return
|
||||||
@ -686,7 +706,7 @@ func (s *Server) onCancelRequest(request *dap.CancelRequest) {
|
|||||||
s.sendNotYetImplementedErrorResponse(request.Request)
|
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 := &dap.ErrorResponse{}
|
||||||
er.Type = "response"
|
er.Type = "response"
|
||||||
er.Command = request.Command
|
er.Command = request.Command
|
||||||
|
|||||||
@ -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) {
|
func TestUnupportedCommandResponses(t *testing.T) {
|
||||||
var got *dap.ErrorResponse
|
var got *dap.ErrorResponse
|
||||||
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
|
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
|
||||||
@ -564,6 +574,18 @@ func TestBadLaunchRequests(t *testing.T) {
|
|||||||
expectFailedToLaunchWithMessage(client.ExpectErrorResponse(t),
|
expectFailedToLaunchWithMessage(client.ExpectErrorResponse(t),
|
||||||
"Failed to launch: Unsupported 'mode' value %!q(float64=12345) in debug configuration.")
|
"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.
|
// Skip detailed message checks for potentially different OS-specific errors.
|
||||||
client.LaunchRequest("exec", fixture.Path+"_does_not_exist", stopOnEntry)
|
client.LaunchRequest("exec", fixture.Path+"_does_not_exist", stopOnEntry)
|
||||||
expectFailedToLaunch(client.ExpectErrorResponse(t))
|
expectFailedToLaunch(client.ExpectErrorResponse(t))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user