@@ -33,9 +33,6 @@ type Module struct {
3333 Name string
3434 // Packages maps import paths to the module's Packages
3535 Packages map [string ]* Pkg
36-
37- // indexed is true after Index() succeeds
38- indexed bool
3936}
4037
4138// getPackageNameFromModPath gets the API review name for the module at modPath
@@ -53,8 +50,7 @@ func getPackageNameFromModPath(modPath string) string {
5350 return modPath
5451}
5552
56- // NewModule constructs a Module, locating its constituent packages but not parsing any source.
57- // Call [Module.Index] to collect type information.
53+ // NewModule indexes a module's ASTs
5854func NewModule (dir string ) (* Module , error ) {
5955 mf , err := parseModFile (dir )
6056 if err != nil {
@@ -97,20 +93,10 @@ func NewModule(dir string) (*Module, error) {
9793 if err != nil {
9894 return nil , err
9995 }
100- return & m , nil
101- }
10296
103- // Index all the types in the module's packages, populating m.Packages and resolving
104- // cross-package type aliases. It adds cross-module aliases to [Module.ExternalAliases]
105- // so callers can later resolve these after indexing referenced external modules.
106- func (m * Module ) Index () {
107- if m .indexed {
108- return
109- }
11097 for _ , p := range m .Packages {
11198 p .Index ()
11299 }
113-
114100 // resolve cross-package references by adding the definitions of types exported by alias to the exporting package
115101 for _ , p := range m .Packages {
116102 for _ , alias := range p .TypeAliases {
@@ -136,7 +122,7 @@ func (m *Module) Index() {
136122 }
137123 }
138124 }
139- m . indexed = true
125+ return & m , nil
140126}
141127
142128// returns the type name for the specified struct field.
0 commit comments