Skip to content

Add createProgram to API - #63950

Draft
Gabriela Araujo Britto (gabritto) wants to merge 3 commits into
mainfrom
gabritto/create_program
Draft

Add createProgram to API#63950
Gabriela Araujo Britto (gabritto) wants to merge 3 commits into
mainfrom
gabritto/create_program

Conversation

@gabritto

@gabritto Gabriela Araujo Britto (gabritto) commented Aug 21, 2026

Copy link
Copy Markdown
Member

This PR adds createProgram to the API (part of #63875).

The API is similar to what we had in Strada, where we take root file names, compiler options, and optionally project references and config file parsing diagnostics, and return a program.
It also optionally takes an oldProgram and file changes to apply to this old program to construct a new program.

Because this API allows you to evolve a program over time by applying changes, its implementation is based on snapshots. So each program returned by this API has a corresponding snapshot to back it. But the process for creating such a snapshot is a little different from the usual: we want this snapshot to back only the one program we're creating. So there's a new snapshot.cloneForProgram just for that. The way it works is that we create a new synthetic inferred project during clone that will contain the root file names and compiler options that were provided via createProgram.

The oldProgram doesn't necessarily have to be created by createProgram either, but it does need to be backed by a server-side snapshot (this may need to change in the future: I'm not sure this would work for the programs created by the upcoming solution builder API).

If an oldProgram isn't provided, we rely on the updated server snapshot as a base for creating the program.

Waiting on #63935 to fix the diagnostics conversion.

@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Aug 21, 2026
@gabritto Gabriela Araujo Britto (gabritto) changed the title add createProgram to API Add createProgram to API Aug 21, 2026
}

projectCollectionBuilder.DidChangeCustomConfigFileName(logger.Fork("DidChangeCustomConfigFileName"))
if change.compilerOptionsForInferredProjects != nil && projectCollectionBuilder.inferredProject.Value() != nil {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by fix.

inferred.Program = project.Program
inferred.ProgramLastUpdate = project.ProgramLastUpdate
inferred.host = project.host
inferred.checkerPool = project.checkerPool

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit awkward to me, but I'm not sure if there's a better way to do this whole thing.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a snapshot-backed createProgram API supporting isolated programs and incremental updates.

Changes:

  • Adds sync/async client APIs and protocol types.
  • Builds synthetic projects with roots, options, references, diagnostics, and file changes.
  • Adds comprehensive API and project tests.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tsc/internal/tsoptions/parsedcommandline.go Adds project references to parsed command lines.
tsc/internal/tsoptions/contentmappers_test.go Updates constructor usage.
tsc/internal/tsoptions/commandlineparser.go Updates constructor usage.
tsc/internal/project/snapshot.go Adds isolated program snapshot cloning.
tsc/internal/project/projectcollectionbuilder.go Supports synthetic inferred-project updates.
tsc/internal/project/project.go Adds reference-aware inferred projects and reuse.
tsc/internal/project/project_test.go Tests inferred compiler-option updates.
tsc/internal/project/api.go Exposes server-side program creation.
tsc/internal/execute/tsc/emit_test.go Updates constructor usage.
tsc/internal/compiler/projectreferenceparser.go Supports reference roots without config files.
tsc/internal/compiler/projectreferencefilemapper.go Handles synthetic root configurations.
tsc/internal/ast/diagnostic.go Adds text-based diagnostic construction.
tsc/internal/api/session.go Handles createProgram requests.
tsc/internal/api/session_createprogram_test.go Tests server-side creation and reuse.
tsc/internal/api/proto.go Defines protocol and diagnostic conversion.
packages/typescript/test/sync/api.test.ts Tests the synchronous API.
packages/typescript/test/async/api.test.ts Tests the asynchronous API.
packages/typescript/src/api/sync/api.ts Adds synchronous createProgram and disposal.
packages/typescript/src/api/proto.generated.ts Adds generated protocol declarations.
packages/typescript/src/api/async/api.ts Adds asynchronous createProgram and disposal.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread tsc/internal/api/proto.go
Comment on lines +1504 to +1507
func (d *DiagnosticResponse) ToDiagnostic() *ast.Diagnostic {
return ast.NewDiagnosticFromText(
nil,
core.NewTextRange(d.Pos, d.End),
Comment on lines +411 to +415
const data: CreateProgramResponse = await this.client.apiRequest("createProgram", {
rootFiles,
createProgramOptions,
...(oldProgram ? { oldProgram: { snapshot: oldProgram.snapshotId, project: oldProgram.getProject().id } } : {}),
...(fileChanges ? { fileChanges } : {}),
Comment on lines +419 to +423
const data: CreateProgramResponse = this.client.apiRequest("createProgram", {
rootFiles,
createProgramOptions,
...(oldProgram ? { oldProgram: { snapshot: oldProgram.snapshotId, project: oldProgram.getProject().id } } : {}),
...(fileChanges ? { fileChanges } : {}),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants