Skip to content

refactor(compiler): introduce TemplateSource abstraction for tsp init#11303

Draft
timotheeguerin wants to merge 4 commits into
mainfrom
tsp-init-template-source
Draft

refactor(compiler): introduce TemplateSource abstraction for tsp init#11303
timotheeguerin wants to merge 4 commits into
mainfrom
tsp-init-template-source

Conversation

@timotheeguerin

Copy link
Copy Markdown
Member

Extracts the self-contained tsp init template-loading refactor out of #11299 into its own PR.

What

Replaces getExecutionRoot()-based template resolution in tsp init with a first-class TemplateSource abstraction, with three implementations behind one interface:

  • FileSystemTemplateSource — the default (installed/node) path; reads templates/ from the compiler package root. No getExecutionRoot() dependency.
  • InMemoryTemplateSource — serves the index and every template file from an in-memory map (used by the standalone single-executable to serve templates offline).
  • RemoteTemplateSource--templates-url; keeps the untrusted-source confirmation and relative-file resolution.

Why

Template loading previously went through the CompilerHost filesystem contract anchored at getExecutionRoot(), which also serves the stdlib. Serving templates from an embedded/offline source required masquerading an in-memory map as a real filesystem and overloading getExecutionRoot(). This refactor decouples template resolution from the host FS contract so each context supplies its own source, and leaves getExecutionRoot() solely for the stdlib.

Notes

Replace getExecutionRoot()-based template loading in `tsp init` with a
first-class TemplateSource abstraction (filesystem, in-memory, and remote
implementations). This decouples template resolution from the CompilerHost
filesystem contract and enables offline/embedded template sources.

Extracted from #11299 as an independent, self-contained refactor.
@microsoft-github-policy-service microsoft-github-policy-service Bot added compiler:core Issues for @typespec/compiler ide Issues for VS, VSCode, Monaco, etc. labels Jul 18, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@11303

commit: 0249d62

@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - internal ✏️

Refactor tsp init template loading around a URI-based TemplateSource abstraction. A UriTemplateSource handles local and remote templates (paths and URLs), while built-in ("core") templates are addressed through an internal: scheme that resolves to an injectable provider. This lets alternative hosts (e.g. an offline single-executable compiler) serve bundled templates via an InMemoryTemplateSource without coupling template loading to the CompilerHost filesystem.

typespec-vscode - internal ✏️

Reuse the compiler's UriTemplateSource.loadIndex() to load tsp init template indexes instead of the extension's own file/URL reading and JSON parsing, unifying how core and configured templates are loaded.

@azure-sdk-automation

azure-sdk-automation Bot commented Jul 18, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

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

Labels

compiler:core Issues for @typespec/compiler ide Issues for VS, VSCode, Monaco, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant