Skip to content

Commit 1c32428

Browse files
committed
copy-paste firelizzard18's suggestion
golang/go#71248 (comment) I basically just copy-pasted and didn't think much. I'm hoping to take a closer look tomorrow or something
1 parent 7d71a0a commit 1c32428

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

gopls/internal/golang/hover.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@ func hover(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, pp pro
258258
// The general case: compute hover information for the object referenced by
259259
// the identifier at pos.
260260
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+
261273
if obj == nil || ident == nil {
262274
return protocol.Range{}, nil, nil // no object to hover
263275
}
@@ -691,11 +703,11 @@ func hoverBuiltin(ctx context.Context, snapshot *cache.Snapshot, obj types.Objec
691703
}, nil
692704
}
693705

694-
// hoverImport computes hover information when hovering over the import path of
706+
// hoverPackageRef computes hover information when hovering over the import path of
695707
// imp in the file pgf of pkg.
696708
//
697709
// 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) {
699711
rng, err := pgf.NodeRange(imp.Path)
700712
if err != nil {
701713
return protocol.Range{}, nil, err
@@ -745,6 +757,22 @@ func hoverImport(ctx context.Context, snapshot *cache.Snapshot, pkg *cache.Packa
745757
}, nil
746758
}
747759

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+
748776
// hoverPackageName computes hover information for the package name of the file
749777
// pgf in pkg.
750778
func hoverPackageName(pkg *cache.Package, pgf *parsego.File) (protocol.Range, *hoverResult, error) {

0 commit comments

Comments
 (0)