From 9df8f1499f10432698ea184c839a2a6f75264e93 Mon Sep 17 00:00:00 2001 From: polinasok <51177946+polinasok@users.noreply.github.com> Date: Thu, 15 Jul 2021 14:15:49 -0700 Subject: [PATCH] service/dap: variables response must not have null variables array (#2592) Co-authored-by: Polina Sokolova --- service/dap/server.go | 6 +++--- service/dap/server_test.go | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/service/dap/server.go b/service/dap/server.go index ad639f70..31331d6e 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -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 == "" { named, err := s.metadataToDAPVariables(v) if err != nil { @@ -1769,7 +1769,7 @@ func (s *Server) childrenToDAPVariables(v *fullyQualifiedVariable) ([]dap.Variab // TODO(polina): consider convertVariableToString instead of convertVariable // and avoid unnecessary creation of variable handles when this is called to // 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 { case reflect.Map: @@ -1917,7 +1917,7 @@ func getNamedVariableCount(v *proc.Variable) int { // metadataToDAPVariables returns the DAP presentation of the referenced variable's metadata. // These are included as named variables 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) { // Return the string value of []byte or []rune. diff --git a/service/dap/server_test.go b/service/dap/server_test.go index 7bd15878..8d57a3c8 100644 --- a/service/dap/server_test.go +++ b/service/dap/server_test.go @@ -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 func checkChildren(t *testing.T, got *dap.VariablesResponse, parentName string, numChildren int) { t.Helper() + if got.Body.Variables == nil { + t.Errorf("\ngot %s children=%#v want []", parentName, got.Body.Variables) + } 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) }