Skip to content

Commit 1e68fee

Browse files
committed
gopls/internal/server: "view package doc" of package under test
When "View package documentation" is invoked in a _test.go file, this change ensures that the documentation for the package under test is displayed, instead of a 404 Not Found. Change-Id: I9c9f2205d6ec72cbe5acea1480acdbf2bd3b8b53 Reviewed-on: https://go-review.googlesource.com/c/tools/+/575695 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent b303e13 commit 1e68fee

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

gopls/internal/server/command.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,13 @@ func (c *commandHandler) Doc(ctx context.Context, loc protocol.Location) error {
512512
return err
513513
}
514514

515+
// When invoked from a _test.go file, show the
516+
// documentation of the package under test.
517+
path := pkg.Metadata().PkgPath
518+
if pkg.Metadata().ForTest != "" {
519+
path = pkg.Metadata().ForTest
520+
}
521+
515522
// Start web server.
516523
web, err := c.s.getWeb()
517524
if err != nil {
@@ -523,7 +530,7 @@ func (c *commandHandler) Doc(ctx context.Context, loc protocol.Location) error {
523530
// TODO(adonovan): compute fragment (e.g. "#fmt.Println") based on loc.Range.
524531
// (Should it document the selected symbol, or the enclosing decl?)
525532
fragment := ""
526-
url := web.pkgURL(deps.snapshot.View(), pkg.Metadata().PkgPath, fragment)
533+
url := web.pkgURL(deps.snapshot.View(), path, fragment)
527534
openClientBrowser(ctx, c.s.client, url)
528535

529536
return nil

0 commit comments

Comments
 (0)