@@ -122,7 +122,7 @@ func parse(glob string) (map[string]*page, tableOfContents, *packages.Module, er
122122
123123 // First, collect all of the files grouped by package, including test
124124 // packages.
125- pkgFiles := map [string ][]string {}
125+ allPkgFiles := map [string ][]string {}
126126 for _ , pkg := range pkgs {
127127 id := pkg .ID
128128 // See https://pkg.go.dev/golang.org/x/tools/go/packages#Config.
@@ -144,17 +144,35 @@ func parse(glob string) (map[string]*page, tableOfContents, *packages.Module, er
144144 for _ , f := range pkg .Syntax {
145145 name := pkg .Fset .File (f .Pos ()).Name ()
146146 if strings .HasSuffix (name , ".go" ) {
147- pkgFiles [id ] = append (pkgFiles [id ], name )
147+ allPkgFiles [id ] = append (allPkgFiles [id ], name )
148+ }
149+ }
150+ }
151+
152+ // Test files don't have Module set. Filter out packages in skipped modules.
153+ pkgFiles := map [string ][]string {}
154+ pkgNames := []string {}
155+ for pkgPath , files := range allPkgFiles {
156+ skip := false
157+ for skipped := range skippedModules {
158+ if strings .HasPrefix (pkgPath , skipped ) {
159+ skip = true
160+ break
148161 }
149162 }
163+ if ! skip {
164+ pkgFiles [pkgPath ] = files
165+ pkgNames = append (pkgNames , pkgPath )
166+ }
150167 }
168+ sort .Strings (pkgNames )
151169
152170 // Once the files are grouped by package, process each package
153171 // independently.
154- for pkgPath , files := range pkgFiles {
172+ for _ , pkgPath := range pkgNames {
155173 parsedFiles := []* ast.File {}
156174 fset := token .NewFileSet ()
157- for _ , f := range files {
175+ for _ , f := range pkgFiles [ pkgPath ] {
158176 pf , err := parser .ParseFile (fset , f , nil , parser .ParseComments )
159177 if err != nil {
160178 return nil , nil , nil , fmt .Errorf ("ParseFile: %v" , err )
@@ -168,6 +186,11 @@ func parse(glob string) (map[string]*page, tableOfContents, *packages.Module, er
168186 return nil , nil , nil , fmt .Errorf ("doc.NewFromFiles: %v" , err )
169187 }
170188
189+ // Extra filter in case the file filtering didn't catch everything.
190+ if ! strings .HasPrefix (docPkg .ImportPath , module .Path ) {
191+ continue
192+ }
193+
171194 toc = append (toc , & tocItem {
172195 UID : docPkg .ImportPath ,
173196 Name : docPkg .ImportPath ,
0 commit comments