@@ -122,7 +122,7 @@ func parse(glob string) (map[string]*page, tableOfContents, *packages.Module, er
122
122
123
123
// First, collect all of the files grouped by package, including test
124
124
// packages.
125
- pkgFiles := map [string ][]string {}
125
+ allPkgFiles := map [string ][]string {}
126
126
for _ , pkg := range pkgs {
127
127
id := pkg .ID
128
128
// 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
144
144
for _ , f := range pkg .Syntax {
145
145
name := pkg .Fset .File (f .Pos ()).Name ()
146
146
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
148
161
}
149
162
}
163
+ if ! skip {
164
+ pkgFiles [pkgPath ] = files
165
+ pkgNames = append (pkgNames , pkgPath )
166
+ }
150
167
}
168
+ sort .Strings (pkgNames )
151
169
152
170
// Once the files are grouped by package, process each package
153
171
// independently.
154
- for pkgPath , files := range pkgFiles {
172
+ for _ , pkgPath := range pkgNames {
155
173
parsedFiles := []* ast.File {}
156
174
fset := token .NewFileSet ()
157
- for _ , f := range files {
175
+ for _ , f := range pkgFiles [ pkgPath ] {
158
176
pf , err := parser .ParseFile (fset , f , nil , parser .ParseComments )
159
177
if err != nil {
160
178
return nil , nil , nil , fmt .Errorf ("ParseFile: %v" , err )
@@ -168,6 +186,11 @@ func parse(glob string) (map[string]*page, tableOfContents, *packages.Module, er
168
186
return nil , nil , nil , fmt .Errorf ("doc.NewFromFiles: %v" , err )
169
187
}
170
188
189
+ // Extra filter in case the file filtering didn't catch everything.
190
+ if ! strings .HasPrefix (docPkg .ImportPath , module .Path ) {
191
+ continue
192
+ }
193
+
171
194
toc = append (toc , & tocItem {
172
195
UID : docPkg .ImportPath ,
173
196
Name : docPkg .ImportPath ,
0 commit comments