@@ -217,7 +217,7 @@ func (tv *tokenVisitor) comment(c *ast.Comment, importByName map[string]*types.P
217
217
case * types.Func :
218
218
return semtok .TokFunction , nil
219
219
case * types.TypeName :
220
- return underlineType ( obj )
220
+ return semtok . TokType , appendTypeModifiers ( nil , obj )
221
221
case * types.Const , * types.Var :
222
222
return semtok .TokVariable , nil
223
223
default :
@@ -484,29 +484,45 @@ func (tv *tokenVisitor) inspect(n ast.Node) (descend bool) {
484
484
return true
485
485
}
486
486
487
- func underlineType (obj types.Object ) (semtok.TokenType , []string ) {
488
- switch obj .Type ().Underlying ().(type ) {
487
+ // appendTypeModifiers appends optional modifiers that describe the top-level
488
+ // type constructor of obj.Type(): "pointer", "map", etc.
489
+ func appendTypeModifiers (mods []string , obj types.Object ) []string {
490
+ switch t := obj .Type ().Underlying ().(type ) {
489
491
case * types.Interface :
490
- return semtok . TokType , [] string { "interface" }
492
+ mods = append ( mods , "interface" )
491
493
case * types.Struct :
492
- return semtok . TokType , [] string { "struct" }
494
+ mods = append ( mods , "struct" )
493
495
case * types.Signature :
494
- return semtok . TokType , [] string { "signature" }
496
+ mods = append ( mods , "signature" )
495
497
case * types.Pointer :
496
- return semtok . TokType , [] string { "pointer" }
498
+ mods = append ( mods , "pointer" )
497
499
case * types.Array :
498
- return semtok . TokType , [] string { "array" }
500
+ mods = append ( mods , "array" )
499
501
case * types.Map :
500
- return semtok . TokType , [] string { "map" }
502
+ mods = append ( mods , "map" )
501
503
case * types.Slice :
502
- return semtok . TokType , [] string { "slice" }
504
+ mods = append ( mods , "slice" )
503
505
case * types.Chan :
504
- return semtok . TokType , [] string { "chan" }
506
+ mods = append ( mods , "chan" )
505
507
case * types.Basic :
506
- return semtok .TokType , []string {"defaultLibrary" }
507
- default :
508
- return semtok .TokType , nil
508
+ mods = append (mods , "defaultLibrary" )
509
+ switch t .Kind () {
510
+ case types .Invalid :
511
+ mods = append (mods , "invalid" )
512
+ case types .String :
513
+ mods = append (mods , "string" )
514
+ case types .Bool :
515
+ mods = append (mods , "bool" )
516
+ case types .UnsafePointer :
517
+ mods = append (mods , "pointer" )
518
+ default :
519
+ info := t .Info ()
520
+ if info == types .IsFloat || info == types .IsComplex || info == types .IsInteger {
521
+ mods = append (mods , "number" )
522
+ }
523
+ }
509
524
}
525
+ return mods
510
526
}
511
527
512
528
func (tv * tokenVisitor ) ident (id * ast.Ident ) {
@@ -562,8 +578,7 @@ func (tv *tokenVisitor) ident(id *ast.Ident) {
562
578
if is [* types.TypeParam ](aliases .Unalias (obj .Type ())) {
563
579
emit (semtok .TokTypeParam )
564
580
} else {
565
- tok , mods := underlineType (obj )
566
- emit (tok , mods ... )
581
+ emit (semtok .TokType , appendTypeModifiers (nil , obj )... )
567
582
}
568
583
case * types.Var :
569
584
if is [* types.Signature ](aliases .Unalias (obj .Type ())) {
@@ -820,15 +835,11 @@ func (tv *tokenVisitor) definitionFor(id *ast.Ident, obj types.Object) (semtok.T
820
835
if fld , ok := fldm .(* ast.Field ); ok {
821
836
// if len(fld.names) == 0 this is a semtok.TokType, being used
822
837
if len (fld .Names ) == 0 {
823
- tok , mods := underlineType (obj )
824
- modifiers = append (modifiers , mods ... )
825
- return tok , modifiers
838
+ return semtok .TokType , appendTypeModifiers (nil , obj )
826
839
}
827
840
return semtok .TokVariable , modifiers
828
841
}
829
- tok , mods := underlineType (obj )
830
- modifiers = append (modifiers , mods ... )
831
- return tok , modifiers
842
+ return semtok .TokType , appendTypeModifiers (modifiers , obj )
832
843
}
833
844
}
834
845
// can't happen
0 commit comments