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 <polinasok@users.noreply.github.com>
This commit is contained in:
polinasok 2020-09-29 07:03:53 -07:00 committed by GitHub
parent 1c4c1fd7fd
commit 551c541737
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

@ -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: <interface{}(int)>
// data: 123
// After:
// i: <interface{}(int)> 123
// Before:
// i: <interface{}(main.MyStruct)>
// data: <main.MyStruct>
// field1: ...
// After:
// i: <interface{}(main.MyStruct)>
// field1: ...
variablesReference = s.variableHandles.create(v)
}
case reflect.Complex64, reflect.Complex128:

@ -909,14 +909,14 @@ func TestScopesAndVariablesRequests2(t *testing.T) {
expectVarExact(t, locals, -1, "fn2", "<main.functype>", noChildren)
// reflect.Kind == Interface
expectVarExact(t, locals, -1, "ifacenil", "nil <interface {}>", noChildren)
ref = expectVarExact(t, locals, -1, "iface2", "<interface {}>", hasChildren)
ref = expectVarExact(t, locals, -1, "iface2", "<interface {}(string)>", 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", "<interface {}>", hasChildren)
ref = expectVarExact(t, locals, -1, "iface4", "<interface {}([]go/constant.Value)>", 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]", "<go/constant.Value>", hasChildren)
expectVarExact(t, iface4data, 0, "[0]", "<go/constant.Value(go/constant.int64Val)>", hasChildren)
}
}
expectVarExact(t, locals, -1, "errnil", "nil <error>", noChildren)
expectVarExact(t, locals, -1, "err1", "<error(*main.astruct)>", hasChildren)
// reflect.Kind == Map
expectVarExact(t, locals, -1, "mnil", "nil <map[string]main.astruct>", noChildren)
ref = expectVarExact(t, locals, -1, "m2", "<map[int]*main.astruct> (length: 1)", hasChildren)