service/dap: variables response must not have null variables array (#2592)

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
This commit is contained in:
polinasok 2021-07-15 14:15:49 -07:00 committed by GitHub
parent 890cde3d4c
commit 9df8f1499f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

@ -1716,7 +1716,7 @@ func (s *Server) onVariablesRequest(request *dap.VariablesRequest) {
} }
} }
var children []dap.Variable children := []dap.Variable{} // must return empty array, not null, if no children
if request.Arguments.Filter == "named" || request.Arguments.Filter == "" { if request.Arguments.Filter == "named" || request.Arguments.Filter == "" {
named, err := s.metadataToDAPVariables(v) named, err := s.metadataToDAPVariables(v)
if err != nil { if err != nil {
@ -1769,7 +1769,7 @@ func (s *Server) childrenToDAPVariables(v *fullyQualifiedVariable) ([]dap.Variab
// TODO(polina): consider convertVariableToString instead of convertVariable // TODO(polina): consider convertVariableToString instead of convertVariable
// and avoid unnecessary creation of variable handles when this is called to // and avoid unnecessary creation of variable handles when this is called to
// compute evaluate names when this is called from onSetVariableRequest. // compute evaluate names when this is called from onSetVariableRequest.
var children []dap.Variable children := []dap.Variable{} // must return empty array, not null, if no children
switch v.Kind { switch v.Kind {
case reflect.Map: case reflect.Map:
@ -1917,7 +1917,7 @@ func getNamedVariableCount(v *proc.Variable) int {
// metadataToDAPVariables returns the DAP presentation of the referenced variable's metadata. // metadataToDAPVariables returns the DAP presentation of the referenced variable's metadata.
// These are included as named variables // These are included as named variables
func (s *Server) metadataToDAPVariables(v *fullyQualifiedVariable) ([]dap.Variable, error) { func (s *Server) metadataToDAPVariables(v *fullyQualifiedVariable) ([]dap.Variable, error) {
var children []dap.Variable children := []dap.Variable{} // must return empty array, not null, if no children
if isListOfBytesOrRunes(v.Variable) { if isListOfBytesOrRunes(v.Variable) {
// Return the string value of []byte or []rune. // Return the string value of []byte or []rune.

@ -658,6 +658,9 @@ func checkScope(t *testing.T, got *dap.ScopesResponse, i int, name string, varRe
// numChildren - number of variables/fields/elements of this variable // numChildren - number of variables/fields/elements of this variable
func checkChildren(t *testing.T, got *dap.VariablesResponse, parentName string, numChildren int) { func checkChildren(t *testing.T, got *dap.VariablesResponse, parentName string, numChildren int) {
t.Helper() t.Helper()
if got.Body.Variables == nil {
t.Errorf("\ngot %s children=%#v want []", parentName, got.Body.Variables)
}
if len(got.Body.Variables) != numChildren { if len(got.Body.Variables) != numChildren {
t.Errorf("\ngot len(%s)=%d (children=%#v)\nwant len=%d", parentName, len(got.Body.Variables), got.Body.Variables, numChildren) t.Errorf("\ngot len(%s)=%d (children=%#v)\nwant len=%d", parentName, len(got.Body.Variables), got.Body.Variables, numChildren)
} }