@@ -97,10 +97,9 @@ func insertDeclsAfter(ctx context.Context, snapshot *cache.Snapshot, mp *metadat
97
97
}
98
98
99
99
newImports := make ([]newImport , 0 , len (declPGF .File .Imports ))
100
- qual := newNamedImportQual (declPGF , snapshot , declMeta , sym , & newImports )
101
- if len (newImports ) != 0 {
102
- println ()
103
- }
100
+ qual := newNamedImportQual (declPGF , snapshot , declMeta , sym , func (imp newImport ) {
101
+ newImports = append (newImports , imp )
102
+ })
104
103
// Compute insertion point for new declarations:
105
104
// after the top-level declaration enclosing the (package-level) type.
106
105
insertOffset , err := safetoken .Offset (declPGF .Tok , declPGF .File .End ())
@@ -226,7 +225,7 @@ func insertStructField(ctx context.Context, snapshot *cache.Snapshot, mp *metada
226
225
return nil , nil , bug .Errorf ("can't find metadata for file %s among dependencies of %s" , declPGF .URI , mp )
227
226
}
228
227
229
- qual := newNamedImportQual (declPGF , snapshot , declMeta , fieldInfo .Named .Obj (), new ([] newImport ))
228
+ qual := newNamedImportQual (declPGF , snapshot , declMeta , fieldInfo .Named .Obj (), func ( imp newImport ) { /* discard */ } )
230
229
231
230
// find the position to insert the new field (end of struct fields)
232
231
insertPos := structType .Fields .Closing - 1
@@ -262,7 +261,7 @@ type newImport struct {
262
261
importPath string
263
262
}
264
263
265
- func newNamedImportQual (declPGF * parsego.File , snapshot * cache.Snapshot , declMeta * metadata.Package , sym types.Object , newImports * [] newImport ) func (* types.Package ) string {
264
+ func newNamedImportQual (declPGF * parsego.File , snapshot * cache.Snapshot , declMeta * metadata.Package , sym types.Object , newImportHandler func ( imp newImport ) ) func (* types.Package ) string {
266
265
// Build import environment for the declaring file.
267
266
// (typesinternal.FileQualifier works only for complete
268
267
// import mappings, and requires types.)
@@ -326,7 +325,7 @@ func newNamedImportQual(declPGF *parsego.File, snapshot *cache.Snapshot, declMet
326
325
if name != pathpkg .Base (trimVersionSuffix (new .importPath )) {
327
326
new .name = name
328
327
}
329
- * newImports = append ( * newImports , new )
328
+ newImportHandler ( new )
330
329
}
331
330
return name
332
331
}
0 commit comments