From 1ac6f7ffda64c739d4e8bf2a6587fd9c8f39ab02 Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Fri, 22 Sep 2023 15:29:33 -0700 Subject: [PATCH] service/dap: add the concrete type to interface type --- service/dap/server.go | 9 +++++++++ service/dap/server_test.go | 16 ++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/service/dap/server.go b/service/dap/server.go index 5bb38f1b9b..c52dcab9d1 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -2509,6 +2509,15 @@ func (s *Session) getTypeIfSupported(v *proc.Variable) string { if !s.clientCapabilities.supportsVariableType { return "" } + switch v.Kind { + case reflect.Interface: + if len(v.Children) > 0 { + vapi := api.ConvertVar(v) + if vapi.Children[0].Kind != reflect.Invalid { + return fmt.Sprintf("%s(%s)", vapi.Type, vapi.Children[0].Type) + } + } + } return v.TypeString() } diff --git a/service/dap/server_test.go b/service/dap/server_test.go index 26b642d733..6517de763f 100644 --- a/service/dap/server_test.go +++ b/service/dap/server_test.go @@ -1719,7 +1719,7 @@ func TestScopesAndVariablesRequests2(t *testing.T) { checkVarExact(t, locals, -1, "fn2", "fn2", "nil", "main.functype", noChildren) // reflect.Kind == Interface checkVarExact(t, locals, -1, "ifacenil", "ifacenil", "interface {} nil", "interface {}", noChildren) - ref = checkVarExact(t, locals, -1, "iface2", "iface2", "interface {}(string) \"test\"", "interface {}", hasChildren) + ref = checkVarExact(t, locals, -1, "iface2", "iface2", "interface {}(string) \"test\"", "interface {}(string)", hasChildren) if ref > 0 { client.VariablesRequest(ref) iface2 := client.ExpectVariablesResponse(t) @@ -1727,7 +1727,7 @@ func TestScopesAndVariablesRequests2(t *testing.T) { checkVarExact(t, iface2, 0, "data", "iface2.(data)", `"test"`, "string", noChildren) validateEvaluateName(t, client, iface2, 0) } - ref = checkVarExact(t, locals, -1, "iface4", "iface4", "interface {}([]go/constant.Value) [4]", "interface {}", hasChildren) + ref = checkVarExact(t, locals, -1, "iface4", "iface4", "interface {}([]go/constant.Value) [4]", "interface {}([]go/constant.Value)", hasChildren) if ref > 0 { client.VariablesRequest(ref) iface4 := client.ExpectVariablesResponse(t) @@ -1737,7 +1737,7 @@ func TestScopesAndVariablesRequests2(t *testing.T) { client.VariablesRequest(ref) iface4data := client.ExpectVariablesResponse(t) checkChildren(t, iface4data, "iface4.data", 1) - ref = checkVarExact(t, iface4data, 0, "[0]", "iface4.(data)[0]", "go/constant.Value(go/constant.int64Val) 4", "go/constant.Value", hasChildren) + ref = checkVarExact(t, iface4data, 0, "[0]", "iface4.(data)[0]", "go/constant.Value(go/constant.int64Val) 4", "go/constant.Value(go/constant.int64Val)", hasChildren) if ref > 0 { client.VariablesRequest(ref) iface4data0 := client.ExpectVariablesResponse(t) @@ -1748,7 +1748,7 @@ func TestScopesAndVariablesRequests2(t *testing.T) { } } checkVarExact(t, locals, -1, "errnil", "errnil", "error nil", "error", noChildren) - ref = checkVarExact(t, locals, -1, "err1", "err1", "error(*main.astruct) *{A: 1, B: 2}", "error", hasChildren) + ref = checkVarExact(t, locals, -1, "err1", "err1", "error(*main.astruct) *{A: 1, B: 2}", "error(*main.astruct)", hasChildren) if ref > 0 { client.VariablesRequest(ref) err1 := client.ExpectVariablesResponse(t) @@ -1761,7 +1761,7 @@ func TestScopesAndVariablesRequests2(t *testing.T) { client.VariablesRequest(ref) ptrinf_val := client.ExpectVariablesResponse(t) checkChildren(t, ptrinf_val, "*ptrinf", 1) - ref = checkVarExact(t, ptrinf_val, 0, "", "(*ptrinf)", "interface {}(**interface {}) **...", "interface {}", hasChildren) + ref = checkVarExact(t, ptrinf_val, 0, "", "(*ptrinf)", "interface {}(**interface {}) **...", "interface {}(**interface {})", hasChildren) if ref > 0 { client.VariablesRequest(ref) ptrinf_val_data := client.ExpectVariablesResponse(t) @@ -2243,7 +2243,7 @@ func TestVariablesLoading(t *testing.T) { // Auto-loading happens here client.VariablesRequest(ref) niI1Data := client.ExpectVariablesResponse(t) - ref = checkVarExact(t, niI1Data, 0, "[0]", "ni[0].(data)[0]", "interface {}(int) 123", "interface {}", hasChildren) + ref = checkVarExact(t, niI1Data, 0, "[0]", "ni[0].(data)[0]", "interface {}(int) 123", "interface {}(int)", hasChildren) if ref > 0 { client.VariablesRequest(ref) niI1DataI2 := client.ExpectVariablesResponse(t) @@ -4370,7 +4370,7 @@ func TestEvaluateCallRequest(t *testing.T) { client.VariablesRequest(ref) rv := client.ExpectVariablesResponse(t) checkChildren(t, rv, "rv", 1) - ref = checkVarExact(t, rv, 0, "~panic", "", `interface {}(string) "callpanic panicked"`, "interface {}", hasChildren) + ref = checkVarExact(t, rv, 0, "~panic", "", `interface {}(string) "callpanic panicked"`, "interface {}(string)", hasChildren) if ref > 0 { client.VariablesRequest(ref) p := client.ExpectVariablesResponse(t) @@ -6027,7 +6027,7 @@ func TestSetVariable(t *testing.T) { tester.evaluate("ifacenil", "interface {}(*main.astruct) *{A: 1, B: 2}", hasChildren) // interface.(data) - iface1Ref := checkVarExact(t, locals, -1, "iface1", "iface1", "interface {}(*main.astruct) *{A: 1, B: 2}", "interface {}", hasChildren) + iface1Ref := checkVarExact(t, locals, -1, "iface1", "iface1", "interface {}(*main.astruct) *{A: 1, B: 2}", "interface {}(*main.astruct)", hasChildren) iface1 := tester.variables(iface1Ref) iface1DataRef := checkVarExact(t, iface1, -1, "data", "iface1.(data)", "*main.astruct {A: 1, B: 2}", "*main.astruct", hasChildren) iface1Data := tester.variables(iface1DataRef)