Skip to content

createProgram - #4914

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

createProgram#4914
Gabriela Araujo Britto (gabritto) wants to merge 10 commits into
mainfrom
gabritto/create_program

Conversation

@gabritto

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

Copy link
Copy Markdown
Member

This PR adds createProgram to the API.

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.

@gabritto Gabriela Araujo Britto (gabritto) added the Unmigrated PR This PR was open at the time of the repo move back to TypeScript label Aug 19, 2026

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 native createProgram support with isolated snapshots, incremental reuse, project references, diagnostics, and sync/async API exposure.

Changes:

  • Adds server protocol and snapshot-backed program creation.
  • Supports old-program reuse, file changes, references, and config diagnostics.
  • Adds Go and TypeScript integration tests.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
internal/tsoptions/parsedcommandline.go Adds project references to parsed command lines.
internal/tsoptions/commandlineparser.go Updates constructor usage.
internal/project/snapshot.go Implements isolated program snapshots.
internal/project/projectcollectionbuilder.go Updates synthetic inferred projects and reuse logic.
internal/project/project.go Adds synthetic-project seeding and metadata propagation.
internal/project/project_test.go Tests inferred-project option updates.
internal/project/api.go Exposes program snapshot creation.
internal/execute/tsc/emit_test.go Updates constructor usage.
internal/compiler/projectreferenceparser.go Supports config-less reference roots.
internal/compiler/projectreferencefilemapper.go Handles synthetic root config paths.
internal/ast/diagnostic.go Adds text-based diagnostic construction.
internal/api/session.go Handles createProgram requests.
internal/api/session_createprogram_test.go Tests creation, reuse, references, and isolation.
internal/api/proto.go Defines protocol types and diagnostic conversion.
_packages/native-preview/test/sync/api.test.ts Adds synchronous API tests.
_packages/native-preview/test/async/api.test.ts Adds asynchronous API tests.
_packages/native-preview/src/api/sync/api.ts Exposes synchronous createProgram.
_packages/native-preview/src/api/proto.ts Adds client protocol types.
_packages/native-preview/src/api/async/api.ts Exposes asynchronous createProgram.

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

Comment thread internal/api/proto.go Outdated
Comment thread internal/api/session.go
Comment thread internal/project/snapshot.go Outdated
Comment thread internal/project/snapshot.go
Comment thread internal/api/proto.go

func (d *DiagnosticResponse) ToDiagnostic() *ast.Diagnostic {
return ast.NewDiagnosticFromText(
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.

I'll need something similar here to what we'll have to do to set up formatDiagnostics, i.e. retrieving a file from the file name associated to a JS-side diagnostic. I'll leave this like that until then.

Comment thread _packages/native-preview/src/api/sync/api.ts
Comment thread _packages/native-preview/src/api/async/api.ts
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
}

projectCollectionBuilder.DidChangeCustomConfigFileName(logger.Fork("DidChangeCustomConfigFileName"))
// compiler options changed, update inferred project and program

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 is a drive-by fix, since I was already working on updateInferredProject.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Unmigrated PR This PR was open at the time of the repo move back to TypeScript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants