From 551c54173718d2962fabbd1af34b93705f6754ac Mon Sep 17 00:00:00 2001 From: polinasok <51177946+polinasok@users.noreply.github.com> Date: Tue, 29 Sep 2020 07:03:53 -0700 Subject: [PATCH] service/dap: make interface variable to dap.Variable conversion more readable (#2184) * Add underlying type when printing interface type * Add todo to remove one level from interface printing Co-authored-by: Polina Sokolova --- service/dap/server.go | 16 +++++++++++++++- service/dap/server_test.go | 8 +++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/service/dap/server.go b/service/dap/server.go index 8c9dc341..62dd14d9 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -962,7 +962,21 @@ func (s *Server) convertVariable(v *proc.Variable) (value string, variablesRefer } else if len(v.Children) == 0 || v.Children[0].Kind == reflect.Invalid && v.Children[0].Addr == 0 { value = "nil <" + typeName + ">" } else { - value = "<" + typeName + ">" + value = "<" + typeName + "(" + v.Children[0].TypeString() + ")" + ">" + // TODO(polina): should we remove one level of indirection and skip "data"? + // Then we will have: + // Before: + // i: + // data: 123 + // After: + // i: 123 + // Before: + // i: + // data: + // field1: ... + // After: + // i: + // field1: ... variablesReference = s.variableHandles.create(v) } case reflect.Complex64, reflect.Complex128: diff --git a/service/dap/server_test.go b/service/dap/server_test.go index fb870627..b2a82d04 100644 --- a/service/dap/server_test.go +++ b/service/dap/server_test.go @@ -909,14 +909,14 @@ func TestScopesAndVariablesRequests2(t *testing.T) { expectVarExact(t, locals, -1, "fn2", "", noChildren) // reflect.Kind == Interface expectVarExact(t, locals, -1, "ifacenil", "nil ", noChildren) - ref = expectVarExact(t, locals, -1, "iface2", "", hasChildren) + ref = expectVarExact(t, locals, -1, "iface2", "", hasChildren) if ref > 0 { client.VariablesRequest(ref) iface2 := client.ExpectVariablesResponse(t) expectChildren(t, iface2, "iface2", 1) expectVarExact(t, iface2, 0, "data", `"test"`, noChildren) } - ref = expectVarExact(t, locals, -1, "iface4", "", hasChildren) + ref = expectVarExact(t, locals, -1, "iface4", "", hasChildren) if ref > 0 { client.VariablesRequest(ref) iface4 := client.ExpectVariablesResponse(t) @@ -926,10 +926,12 @@ func TestScopesAndVariablesRequests2(t *testing.T) { client.VariablesRequest(ref) iface4data := client.ExpectVariablesResponse(t) expectChildren(t, iface4data, "iface4.data", 1) - expectVarExact(t, iface4data, 0, "[0]", "", hasChildren) + expectVarExact(t, iface4data, 0, "[0]", "", hasChildren) } } + expectVarExact(t, locals, -1, "errnil", "nil ", noChildren) + expectVarExact(t, locals, -1, "err1", "", hasChildren) // reflect.Kind == Map expectVarExact(t, locals, -1, "mnil", "nil ", noChildren) ref = expectVarExact(t, locals, -1, "m2", " (length: 1)", hasChildren)