@@ -117,6 +117,16 @@ func HoverIdentifier(ctx context.Context, i *IdentifierInfo) (*HoverInformation,
117
117
}
118
118
h .Signature = prefix + h .Signature
119
119
}
120
+
121
+ // Check if the variable is an integer whose value we can present in a more
122
+ // user-friendly way, i.e. `var hex = 0xe34e` becomes `var hex = 58190`
123
+ if spec , ok := x .(* ast.ValueSpec ); ok && len (spec .Values ) > 0 {
124
+ if lit , ok := spec .Values [0 ].(* ast.BasicLit ); ok && len (spec .Names ) > 0 {
125
+ val := constant .MakeFromLiteral (types .ExprString (lit ), lit .Kind , 0 )
126
+ h .Signature = fmt .Sprintf ("var %s = %s" , spec .Names [0 ], val )
127
+ }
128
+ }
129
+
120
130
case types.Object :
121
131
// If the variable is implicitly declared in a type switch, we need to
122
132
// manually generate its object string.
@@ -454,6 +464,15 @@ func formatVar(node ast.Spec, obj types.Object, decl *ast.GenDecl) *HoverInforma
454
464
if comment == nil {
455
465
comment = spec .Comment
456
466
}
467
+
468
+ // We need the AST nodes for variable declarations of basic literals with
469
+ // associated values so that we can augment their hover with more information.
470
+ if _ , ok := obj .(* types.Var ); ok && spec .Type == nil && len (spec .Values ) > 0 {
471
+ if _ , ok := spec .Values [0 ].(* ast.BasicLit ); ok {
472
+ return & HoverInformation {source : spec , comment : comment }
473
+ }
474
+ }
475
+
457
476
return & HoverInformation {source : obj , comment : comment }
458
477
}
459
478
0 commit comments