type refreshTimer … // newRefreshTimer constructs a new refresh timer which schedules refreshes // using the given function. func newRefreshTimer(refresh func()) *refreshTimer { … } // stop stops any future scheduled refresh. func (t *refreshTimer) stop() { … } // schedule schedules the refresh function to run at some point in the future, // if no existing refresh is already scheduled. // // At a minimum, scheduled refreshes are delayed by 30s, but they may be // delayed longer to keep their expected execution time under 2% of wall clock // time. func (t *refreshTimer) schedule() { … } type sharedModCache … func (c *sharedModCache) dirCache(dir string) *imports.DirInfoCache { … } // refreshDir schedules a refresh of the given directory, which must be a // module cache. func (c *sharedModCache) refreshDir(ctx context.Context, dir string, logf func(string, ...any)) { … } type importsState … // newImportsState constructs a new imports state for running goimports // functions via [runProcessEnvFunc]. // // The returned state will automatically refresh itself following a delay. func newImportsState(backgroundCtx context.Context, modCache *sharedModCache, env *imports.ProcessEnv) *importsState { … } // stopTimer stops scheduled refreshes of this imports state. func (s *importsState) stopTimer() { … } // runProcessEnvFunc runs goimports. // // Any call to runProcessEnvFunc will schedule a refresh of the imports state // at some point in the future, if such a refresh is not already scheduled. See // [refreshTimer] for more details. func (s *importsState) runProcessEnvFunc(ctx context.Context, snapshot *Snapshot, fn func(context.Context, *imports.Options) error) error { … } func (s *importsState) refreshProcessEnv() { … }