()
| 349 | } |
| 350 | |
| 351 | func (p *Project) CreateProgram() CreateProgramResult { |
| 352 | updateKind := ProgramUpdateKindNewFiles |
| 353 | var programCloned bool |
| 354 | var newProgram *compiler.Program |
| 355 | |
| 356 | // Define a fresh CreateCheckerPool closure for this call. Each invocation of |
| 357 | // CreateProgram must use its own closure so that concurrent goroutines cloning |
| 358 | // the same project never share a captured variable through a stale closure |
| 359 | // stored in the old program's options. |
| 360 | createCheckerPool := func(program *compiler.Program) compiler.CheckerPool { |
| 361 | return newCheckerPool(p.host.sessionOptions.CheckerPoolOptions, program, p.log) |
| 362 | } |
| 363 | |
| 364 | // Create the command line, potentially augmented with typing files |
| 365 | commandLine := p.getCommandLineWithTypingsFiles() |
| 366 | |
| 367 | if p.dirtyFilePath != "" && p.Program != nil && p.Program.CommandLine() == commandLine { |
| 368 | var dirtyFile *ast.SourceFile |
| 369 | newProgram, dirtyFile, programCloned = p.Program.UpdateProgram(p.dirtyFilePath, p.host, createCheckerPool) |
| 370 | if programCloned { |
| 371 | updateKind = ProgramUpdateKindCloned |
| 372 | for _, file := range newProgram.SourceFiles() { |
| 373 | // Use pointer identity: dirtyFile is the exact instance UpdateProgram acquired, |
| 374 | // and it is the only file whose refcount is already accounted for. |
| 375 | if file != dirtyFile { |
| 376 | // UpdateProgram acquired the changed file only, so we need to ref everything else |
| 377 | p.host.builder.parseCache.Ref(NewParseCacheKey(file.ParseOptions(), file.Hash, file.ScriptKind)) |
| 378 | } |
| 379 | } |
| 380 | for _, file := range newProgram.DuplicateSourceFiles() { |
| 381 | p.host.builder.parseCache.Ref(NewParseCacheKey(file.ParseOptions, file.Hash, file.ScriptKind)) |
| 382 | } |
| 383 | } else if dirtyFile != nil { |
| 384 | // UpdateProgram always acquires the dirty file before deciding whether it can |
| 385 | // reuse the old program. If it falls back to a full rebuild, release that |
| 386 | // speculative acquire so the rebuilt program is the only remaining owner. |
| 387 | p.host.builder.parseCache.Deref(NewParseCacheKey(dirtyFile.ParseOptions(), dirtyFile.Hash, dirtyFile.ScriptKind)) |
| 388 | } |
| 389 | } else { |
| 390 | var typingsLocation string |
| 391 | if p.GetTypeAcquisition().Enable.IsTrue() { |
| 392 | typingsLocation = p.host.sessionOptions.TypingsLocation |
| 393 | } |
| 394 | newProgram = compiler.NewProgram( |
| 395 | compiler.ProgramOptions{ |
| 396 | Host: p.host, |
| 397 | Config: commandLine, |
| 398 | UseSourceOfProjectReference: true, |
| 399 | TypingsLocation: typingsLocation, |
| 400 | CreateCheckerPool: createCheckerPool, |
| 401 | }, |
| 402 | ) |
| 403 | } |
| 404 | |
| 405 | if !programCloned && p.Program != nil && p.Program.HasSameFileNames(newProgram) { |
| 406 | updateKind = ProgramUpdateKindSameFileNames |
| 407 | } |
| 408 |
no test coverage detected