From b72bce30cce71cf3ba81bbd96ed87b54d9ccb3d2 Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Wed, 19 May 2021 14:17:36 -0400 Subject: [PATCH] service/dap: support evaluate for hover context (#2496) We can support evaluate for hover context in order to provide more useful hover info for our users. Updates go-delve/delve#2491 Updates golang/vscode-go#1510 --- service/dap/daptest/client.go | 1 + service/dap/server.go | 3 ++- service/dap/server_test.go | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/service/dap/daptest/client.go b/service/dap/daptest/client.go index fc3d7dcc..180b6161 100644 --- a/service/dap/daptest/client.go +++ b/service/dap/daptest/client.go @@ -102,6 +102,7 @@ func (c *Client) ExpectInitializeResponseAndCapabilities(t *testing.T) *dap.Init SupportTerminateDebuggee: true, SupportsExceptionInfoRequest: true, SupportsFunctionBreakpoints: true, + SupportsEvaluateForHovers: true, } if !reflect.DeepEqual(initResp.Body, wantCapabilities) { t.Errorf("capabilities in initializeResponse: got %+v, want %v", pretty(initResp.Body), pretty(wantCapabilities)) diff --git a/service/dap/server.go b/service/dap/server.go index 085d0db9..28166c03 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -677,6 +677,7 @@ func (s *Server) onInitializeRequest(request *dap.InitializeRequest) { response.Body.SupportTerminateDebuggee = true response.Body.SupportsFunctionBreakpoints = true response.Body.SupportsExceptionInfoRequest = true + response.Body.SupportsEvaluateForHovers = true // TODO(polina): support this to match vscode-go functionality response.Body.SupportsSetVariable = false // TODO(polina): support these requests in addition to vscode-go feature parity @@ -1755,7 +1756,7 @@ func (s *Server) convertVariableWithOpts(v *proc.Variable, qualifiedNameOrExpr s // variables, so consider also adding the following: // -- print {expression} - return the result as a string like from dlv cli func (s *Server) onEvaluateRequest(request *dap.EvaluateRequest) { - showErrorToUser := request.Arguments.Context != "watch" && request.Arguments.Context != "repl" + showErrorToUser := request.Arguments.Context != "watch" && request.Arguments.Context != "repl" && request.Arguments.Context != "hover" if s.debugger == nil { s.sendErrorResponseWithOpts(request.Request, UnableToEvaluateExpression, "Unable to evaluate expression", "debugger is nil", showErrorToUser) return diff --git a/service/dap/server_test.go b/service/dap/server_test.go index dc66c2c8..e41769ce 100644 --- a/service/dap/server_test.go +++ b/service/dap/server_test.go @@ -2560,6 +2560,16 @@ func TestEvaluateRequest(t *testing.T) { if erres.Body.Error.Format != "Unable to evaluate expression: could not find symbol value for a1" { t.Errorf("\ngot %#v\nwant Format=\"Unable to evaluate expression: could not find symbol value for a1\"", erres) } + client.EvaluateRequest("a1", 1002, "repl") + erres = client.ExpectInvisibleErrorResponse(t) + if erres.Body.Error.Format != "Unable to evaluate expression: could not find symbol value for a1" { + t.Errorf("\ngot %#v\nwant Format=\"Unable to evaluate expression: could not find symbol value for a1\"", erres) + } + client.EvaluateRequest("a1", 1002, "hover") + erres = client.ExpectInvisibleErrorResponse(t) + if erres.Body.Error.Format != "Unable to evaluate expression: could not find symbol value for a1" { + t.Errorf("\ngot %#v\nwant Format=\"Unable to evaluate expression: could not find symbol value for a1\"", erres) + } }, disconnect: false, }})