internal/localdatasource: use CandidateModulePaths

Use the internal.CandidateModulePaths function in findModule.

For golang/go#47780

Change-Id: I0bf717052719c9583fd2066465f08471fb06402f
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/344529
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/internal/localdatasource/datasource.go b/internal/localdatasource/datasource.go
index bc08c21..6cb1e6b 100644
--- a/internal/localdatasource/datasource.go
+++ b/internal/localdatasource/datasource.go
@@ -12,7 +12,6 @@
 	"errors"
 	"fmt"
 	"os"
-	"path"
 	"path/filepath"
 	"strings"
 	"sync"
@@ -188,14 +187,13 @@
 // findModule finds the module with longest module path containing the given
 // package path. It returns an error if no module is found.
 func (ds *DataSource) findModule(ctx context.Context, pkgPath, modulePath, version string) (_ *internal.Module, err error) {
-	defer derrors.Wrap(&err, "findModule(%q)", pkgPath)
+	defer derrors.Wrap(&err, "findModule(%q, %q, %q)", pkgPath, modulePath, version)
 
 	if modulePath != internal.UnknownModulePath {
 		return ds.getModule(ctx, modulePath, version)
 	}
-
 	pkgPath = strings.TrimLeft(pkgPath, "/")
-	for modulePath := pkgPath; modulePath != "" && modulePath != "."; modulePath = path.Dir(modulePath) {
+	for _, modulePath := range internal.CandidateModulePaths(pkgPath) {
 		m, err := ds.getModule(ctx, modulePath, version)
 		if err == nil {
 			return m, nil