@@ -281,7 +281,11 @@ func NewProgram(opts ProgramOptions) *Program {
281281// In addition to a new program, return a boolean indicating whether the data of the old program was reused.
282282// createCheckerPool, if non-nil, overrides the CreateCheckerPool stored in the old program's options,
283283// ensuring each caller uses a fresh closure and avoiding data races on captured variables.
284- func (p * Program ) UpdateProgram (changedFilePath tspath.Path , newHost CompilerHost , createCheckerPool func (* Program ) CheckerPool ) (* Program , bool ) {
284+ // The returned *ast.SourceFile is the changed file as acquired through newHost; it is nil
285+ // only if the host cannot locate the file (e.g. it was deleted). Callers that manage
286+ // host-side parse caches must release this exact pointer when the old program could not be
287+ // reused, since it was acquired speculatively before that decision was made.
288+ func (p * Program ) UpdateProgram (changedFilePath tspath.Path , newHost CompilerHost , createCheckerPool func (* Program ) CheckerPool ) (* Program , * ast.SourceFile , bool ) {
285289 newOpts := p .opts
286290 newOpts .Host = newHost
287291 if createCheckerPool != nil {
@@ -297,11 +301,11 @@ func (p *Program) UpdateProgram(changedFilePath tspath.Path, newHost CompilerHos
297301 _ , inRedirectFiles := p .redirectFilesByPath [changedFilePath ]
298302 _ , isRedirectTarget := p .redirectTargetsMap [changedFilePath ]
299303 if inRedirectFiles || isRedirectTarget {
300- return NewProgram (newOpts ), false
304+ return NewProgram (newOpts ), newFile , false
301305 }
302306
303307 if ! canReplaceFileInProgram (oldFile , newFile ) {
304- return NewProgram (newOpts ), false
308+ return NewProgram (newOpts ), newFile , false
305309 }
306310 // TODO: reverify compiler options when config has changed?
307311 result := & Program {
@@ -322,7 +326,7 @@ func (p *Program) UpdateProgram(changedFilePath tspath.Path, newHost CompilerHos
322326 result .filesByPath = maps .Clone (result .filesByPath )
323327 result .filesByPath [newFile .Path ()] = newFile
324328 updateFileIncludeProcessor (result )
325- return result , true
329+ return result , newFile , true
326330}
327331
328332func (p * Program ) initCheckerPool () {
0 commit comments