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 2 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
|
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.API
A library exports an
$onInfoprovider (using thedefineInfoHooktyping helper). The hook receives anInfoContext({ program, target }) and returns a singleTypeInfo({ content: string }) orundefined:Tooling / the language server queries it. Contributions from every library are merged into a single
TypeInfo(orundefinedwhen nothing is contributed or the feature is disabled):Enable it in
tspconfig.yaml:@typespec/httpreference provider@typespec/httpnow ships an$onInfoprovider that surfaces the resolved HTTP route (verb + URI template) and response status codes of an operation.Changes
$onInfohook,defineInfoHookhelper,InfoContext/TypeInfo/OnInfoHooktypes,program.getTypeInfo, binder auto-discovery,type-info-hookfeature flag, LSP hover wiring.$onInfoprovider (verb + URI template + response status codes).Testing
packages/compiler/test/info-hook.test.ts(merge, no-contributor, feature-disabled, provider-crash).get-hover.test.tsto cover hover enrichment.packages/http/test/info.test.ts.