service/dap: truncate value for expandable types in hover (#2529)

On hovers, including the full value for complex types is unnecessary, since the user will likely need to expand the children to inspect the values. Additionally, this can really slow down getting the hover values. This change will allow truncating the value in hover if the variable has a variables reference.

Updates golang/vscode-go#1435
This commit is contained in:
Suzy Mueller
2021-06-11 13:46:49 -04:00
committed by GitHub
parent aa377789b0
commit 688f94a4f8
2 changed files with 7 additions and 2 deletions

View File

@ -2045,6 +2045,9 @@ func (s *Server) convertVariableWithOpts(v *proc.Variable, qualifiedNameOrExpr s
variablesReference = maybeCreateVariableHandle(v)
}
}
// By default, only values of variables that have children can be truncated.
// If showFullValue is set, then all value strings are not truncated.
canTruncateValue := showFullValue&opts == 0
if len(value) > defaultMaxValueLen && canTruncateValue && canHaveRef {
value = value[:defaultMaxValueLen] + "..."
@ -2123,7 +2126,9 @@ func (s *Server) onEvaluateRequest(request *dap.EvaluateRequest) {
}
}
var opts convertVariableFlags
if ctxt == "variables" || ctxt == "hover" || ctxt == "clipboard" {
// Send the full value when the context is "clipboard" or "variables" since
// these contexts are used to copy the value.
if ctxt == "clipboard" || ctxt == "variables" {
opts |= showFullValue
}
exprVal, exprRef := s.convertVariableWithOpts(exprVar, fmt.Sprintf("(%s)", request.Arguments.Expression), opts)

View File

@ -2883,7 +2883,7 @@ func TestEvaluateRequestLongStrLargeValue(t *testing.T) {
got3 := client.ExpectEvaluateResponse(t)
want3 := m1Truncated
switch evalContext {
case "variables", "hover", "clipboard":
case "variables", "clipboard":
want3 = m1
}
checkEvalRegex(t, got3, want3, true)