Skip to content

Commit e295569

Browse files
committed
Use callback instead of a slice pointer
1 parent 0be5d8d commit e295569

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

gopls/internal/golang/stub.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@ func insertDeclsAfter(ctx context.Context, snapshot *cache.Snapshot, mp *metadat
9797
}
9898

9999
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+
})
104103
// Compute insertion point for new declarations:
105104
// after the top-level declaration enclosing the (package-level) type.
106105
insertOffset, err := safetoken.Offset(declPGF.Tok, declPGF.File.End())
@@ -226,7 +225,7 @@ func insertStructField(ctx context.Context, snapshot *cache.Snapshot, mp *metada
226225
return nil, nil, bug.Errorf("can't find metadata for file %s among dependencies of %s", declPGF.URI, mp)
227226
}
228227

229-
qual := newNamedImportQual(declPGF, snapshot, declMeta, fieldInfo.Named.Obj(), new([]newImport))
228+
qual := newNamedImportQual(declPGF, snapshot, declMeta, fieldInfo.Named.Obj(), func(imp newImport) { /* discard */ })
230229

231230
// find the position to insert the new field (end of struct fields)
232231
insertPos := structType.Fields.Closing - 1
@@ -262,7 +261,7 @@ type newImport struct {
262261
importPath string
263262
}
264263

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 {
266265
// Build import environment for the declaring file.
267266
// (typesinternal.FileQualifier works only for complete
268267
// import mappings, and requires types.)
@@ -326,7 +325,7 @@ func newNamedImportQual(declPGF *parsego.File, snapshot *cache.Snapshot, declMet
326325
if name != pathpkg.Base(trimVersionSuffix(new.importPath)) {
327326
new.name = name
328327
}
329-
*newImports = append(*newImports, new)
328+
newImportHandler(new)
330329
}
331330
return name
332331
}

0 commit comments

Comments
 (0)