@@ -258,6 +258,18 @@ func hover(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, pp pro
258
258
// The general case: compute hover information for the object referenced by
259
259
// the identifier at pos.
260
260
ident , obj , selectedType := referencedObject (pkg , pgf , pos )
261
+
262
+ if _ , ok := obj .(* types.PkgName ); ok {
263
+ rng , hoverRes , err := hoverPackageIdent (ctx , snapshot , pkg , pgf )
264
+ if err != nil {
265
+ return protocol.Range {}, nil , err
266
+ }
267
+ if hoverRange == nil {
268
+ hoverRange = & rng
269
+ }
270
+ return * hoverRange , hoverRes , nil // (hoverRes may be nil)
271
+ }
272
+
261
273
if obj == nil || ident == nil {
262
274
return protocol.Range {}, nil , nil // no object to hover
263
275
}
@@ -691,11 +703,11 @@ func hoverBuiltin(ctx context.Context, snapshot *cache.Snapshot, obj types.Objec
691
703
}, nil
692
704
}
693
705
694
- // hoverImport computes hover information when hovering over the import path of
706
+ // hoverPackageRef computes hover information when hovering over the import path of
695
707
// imp in the file pgf of pkg.
696
708
//
697
709
// If we do not have metadata for the hovered import, it returns _
698
- func hoverImport (ctx context.Context , snapshot * cache.Snapshot , pkg * cache.Package , pgf * parsego.File , imp * ast.ImportSpec ) (protocol.Range , * hoverResult , error ) {
710
+ func hoverPackageRef (ctx context.Context , snapshot * cache.Snapshot , pkg * cache.Package , pgf * parsego.File , imp * ast.ImportSpec ) (protocol.Range , * hoverResult , error ) {
699
711
rng , err := pgf .NodeRange (imp .Path )
700
712
if err != nil {
701
713
return protocol.Range {}, nil , err
@@ -745,6 +757,22 @@ func hoverImport(ctx context.Context, snapshot *cache.Snapshot, pkg *cache.Packa
745
757
}, nil
746
758
}
747
759
760
+ // hoverImport computes hover information when hovering over the import path of
761
+ // imp in the file pgf of pkg.
762
+ //
763
+ // If we do not have metadata for the hovered import, it returns _
764
+ func hoverImport (ctx context.Context , snapshot * cache.Snapshot , pkg * cache.Package , pgf * parsego.File , imp * ast.ImportSpec ) (protocol.Range , * hoverResult , error ) {
765
+ return hoverPackageRef (ctx , snapshot , pkg , pgf , imp )
766
+ }
767
+
768
+ // hoverPackageIdent computes hover information when hovering over the import path of
769
+ // imp in the file pgf of pkg.
770
+ //
771
+ // If we do not have metadata for the hovered import, it returns _
772
+ func hoverPackageIdent (ctx context.Context , snapshot * cache.Snapshot , pkg * cache.Package , pgf * parsego.File ) (protocol.Range , * hoverResult , error ) {
773
+ return hoverPackageRef (ctx , snapshot , pkg , pgf , imp )
774
+ }
775
+
748
776
// hoverPackageName computes hover information for the package name of the file
749
777
// pgf in pkg.
750
778
func hoverPackageName (pkg * cache.Package , pgf * parsego.File ) (protocol.Range , * hoverResult , error ) {
0 commit comments