feat(compiler): add experimental $onInfo hook and program.getTypeInfo API - #11489
feat(compiler): add experimental $onInfo hook and program.getTypeInfo API#11489timotheeguerin wants to merge 6 commits into
Conversation
… API Add a new experimental `$onInfo` library hook (gated behind the `type-info-hook` compiler feature flag) and `program.getTypeInfo(type)` API allowing libraries to contribute extra, domain-specific info about types for IDE hover and tooling. Wire it into LSP hover and add a `@typespec/http` provider surfacing verb + URI template + response status codes.
commit: |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
The `type-info-hook` feature is now checked against the package that declares the $onInfo hook rather than the consuming project. Libraries opt in via their own tspconfig.yaml and consumers see the info without enabling anything. Enable it in @typespec/http and ship library tspconfig.yaml in bundles so it works in the playground.
| @@ -0,0 +1,93 @@ | |||
| --- | |||
| id: providing-info | |||
There was a problem hiding this comment.
can we add experimental badge to sidebar?
There was a problem hiding this comment.
Done — the sidebar entry is now a SlugItem with badge: { text: "experimental", variant: "caution" } (matching the variant used for alpha/beta libraries).
- Report a dedicated `on-info-fail` diagnostic when an `$onInfo` provider crashes during a design-time build, instead of reusing the misleading `on-validate-fail` code. - Use vitest `expect` in the new info hook tests. - Badge the "Providing info" docs page as experimental in the sidebar.
The `type-info-hook` opt-in is resolved from the declaring package's own config, but `tspconfig.yaml` was missing from `package.json#files`, so the hook was silently dropped for anyone installing @typespec/http from a registry. It only ever worked inside the monorepo. Other review feedback: - `getTypeInfo` no longer reports diagnostics after compilation finished; it traces instead, so a crashing provider cannot accumulate duplicates on a cached Program or flip `continueToNextStage`. Drops the now unused `on-info-fail` diagnostic. - Fix the `defineInfoHook` JSDoc example, which returned an array and did not type check against `OnInfoHook`. - Add an end-to-end test exercising the real registration path, plus coverage for the status code range and `*` branches. - Fix a broken link to the configuration docs and document that a library must ship its `tspconfig.yaml`.
Fixes #1993
Summary
Adds a new experimental
$onInfolibrary hook andprogram.getTypeInfo(type)API that lets libraries contribute extra, domain-specific information about types. This information is surfaced in IDE hover tooltips and can be queried programmatically by tooling (e.g. AI agents).Unlike
$onValidate, this hook:The feature is gated behind a new

type-info-hookcompiler feature flag.