Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service/dap: add the concrete type to interface type #3510

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
16 changes: 8 additions & 8 deletions service/dap/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1719,15 +1719,15 @@ 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)
checkChildren(t, iface2, "iface2", 1)
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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down