Skip to content

Commit 13887f5

Browse files
committed
eh, NewModule can do work
1 parent acc384f commit 13887f5

File tree

2 files changed

+3
-25
lines changed

2 files changed

+3
-25
lines changed

src/go/cmd/module.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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
5854
func 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.

src/go/cmd/review.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ func (r *Review) AddModule(m *Module) error {
5050
if _, ok := r.modules[m.ModFile.Module.Mod.Path]; ok {
5151
return fmt.Errorf("module %s already exists in index", m.ModFile.Module.Mod.Path)
5252
}
53-
m.Index()
5453
if len(r.modules) == 0 {
5554
r.reviewed = m
5655
}
@@ -59,7 +58,7 @@ func (r *Review) AddModule(m *Module) error {
5958
}
6059

6160
func (r *Review) Review() (PackageReview, error) {
62-
r.index()
61+
r.resolveAliases()
6362

6463
tokenList := &[]Token{}
6564
nav := []Navigation{}
@@ -127,13 +126,6 @@ func (r *Review) Review() (PackageReview, error) {
127126
}, nil
128127
}
129128

130-
func (r *Review) index() {
131-
for _, m := range r.modules {
132-
m.Index()
133-
}
134-
r.resolveAliases()
135-
}
136-
137129
// findLocalModule tries to find the source module defining a type in the same repository as
138130
// the reviewed module. Returns errExternalModule if the source module is in a different repository.
139131
func (r *Review) findLocalModule(ta TypeAlias) (*Module, error) {

0 commit comments

Comments
 (0)