mirror of
https://github.com/go-delve/delve.git
synced 2025-10-28 04:35:19 +08:00
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:
@ -2045,6 +2045,9 @@ func (s *Server) convertVariableWithOpts(v *proc.Variable, qualifiedNameOrExpr s
|
|||||||
variablesReference = maybeCreateVariableHandle(v)
|
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
|
canTruncateValue := showFullValue&opts == 0
|
||||||
if len(value) > defaultMaxValueLen && canTruncateValue && canHaveRef {
|
if len(value) > defaultMaxValueLen && canTruncateValue && canHaveRef {
|
||||||
value = value[:defaultMaxValueLen] + "..."
|
value = value[:defaultMaxValueLen] + "..."
|
||||||
@ -2123,7 +2126,9 @@ func (s *Server) onEvaluateRequest(request *dap.EvaluateRequest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var opts convertVariableFlags
|
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
|
opts |= showFullValue
|
||||||
}
|
}
|
||||||
exprVal, exprRef := s.convertVariableWithOpts(exprVar, fmt.Sprintf("(%s)", request.Arguments.Expression), opts)
|
exprVal, exprRef := s.convertVariableWithOpts(exprVar, fmt.Sprintf("(%s)", request.Arguments.Expression), opts)
|
||||||
|
|||||||
@ -2883,7 +2883,7 @@ func TestEvaluateRequestLongStrLargeValue(t *testing.T) {
|
|||||||
got3 := client.ExpectEvaluateResponse(t)
|
got3 := client.ExpectEvaluateResponse(t)
|
||||||
want3 := m1Truncated
|
want3 := m1Truncated
|
||||||
switch evalContext {
|
switch evalContext {
|
||||||
case "variables", "hover", "clipboard":
|
case "variables", "clipboard":
|
||||||
want3 = m1
|
want3 = m1
|
||||||
}
|
}
|
||||||
checkEvalRegex(t, got3, want3, true)
|
checkEvalRegex(t, got3, want3, true)
|
||||||
|
|||||||
Reference in New Issue
Block a user