Skip to content

feat(compiler): add experimental $onInfo hook and program.getTypeInfo API - #11489

Draft
timotheeguerin wants to merge 2 commits into
microsoft:mainfrom
timotheeguerin:on-info
Draft

feat(compiler): add experimental $onInfo hook and program.getTypeInfo API#11489
timotheeguerin wants to merge 2 commits into
microsoft:mainfrom
timotheeguerin:on-info

Conversation

@timotheeguerin

Copy link
Copy Markdown
Member

Fixes #1993

Summary

Adds a new experimental $onInfo library hook and program.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:

  • is never run during compilation — it is invoked lazily and on demand.
  • must not mutate the type graph — it only reads the program to answer questions about a type.

The feature is gated behind a new type-info-hook compiler feature flag.

API

A library exports an $onInfo provider (using the defineInfoHook typing helper). The hook receives an InfoContext ({ program, target }) and returns a single TypeInfo ({ content: string }) or undefined:

import { defineInfoHook } from "@typespec/compiler";

export const $onInfo = defineInfoHook(({ program, target }) => {
  if (target.kind !== "Operation") return undefined;
  return { content: "extra info about this operation" };
});

Tooling / the language server queries it. Contributions from every library are merged into a single TypeInfo (or undefined when nothing is contributed or the feature is disabled):

const info = program.getTypeInfo(type);
// { content: "`HTTP Route`: `GET /pets/{id}`\n\n`Responses`: `204`" }

Enable it in tspconfig.yaml:

features:
  - type-info-hook

@typespec/http reference provider

@typespec/http now ships an $onInfo provider that surfaces the resolved HTTP route (verb + URI template) and response status codes of an operation.

Changes

  • compiler: $onInfo hook, defineInfoHook helper, InfoContext/TypeInfo/OnInfoHook types, program.getTypeInfo, binder auto-discovery, type-info-hook feature flag, LSP hover wiring.
  • http: $onInfo provider (verb + URI template + response status codes).
  • docs: new "Providing IDE & tooling info" extending-typespec page.

Testing

  • New packages/compiler/test/info-hook.test.ts (merge, no-contributor, feature-disabled, provider-crash).
  • Updated get-hover.test.ts to cover hover enrichment.
  • New packages/http/test/info.test.ts.

… 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.
@microsoft-github-policy-service microsoft-github-policy-service Bot added compiler:core Issues for @typespec/compiler lib:http meta:website TypeSpec.io updates labels Jul 30, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: ddd2cac

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/compiler
  • @typespec/http
Show changes

@typespec/compiler - feature ✏️

Add a new experimental $onInfo library hook and program.getTypeInfo(type) API allowing libraries to contribute extra, domain-specific information about types. Unlike $onValidate, this hook never runs during compilation and must not mutate the type graph — it is invoked lazily and on demand (e.g. by the language server for hover documentation, or by tooling querying the type). The feature is gated behind the type-info-hook compiler feature flag.,> ,> ts,> // A library exports a provider (use `defineInfoHook` for typing):,> export const $onInfo = defineInfoHook(({ program, target }) => {,> if (target.kind !== "Operation") return undefined;,> return { content: "extra info about this operation" };,> });,> ,> // Tooling / language server queries it (merges every library's contribution):,> const info = program.getTypeInfo(type);,>

@typespec/http - feature ✏️

Add an $onInfo provider that surfaces the resolved HTTP route (verb and URI template) and response status codes of an operation. This is shown when hovering an operation in the IDE and can be queried programmatically via program.getTypeInfo(operation). Requires the experimental type-info-hook compiler feature flag.

@azure-sdk-automation

azure-sdk-automation Bot commented Jul 30, 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 lib:http meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mechanism for libraries to add information to IDE documentation/tooltip

1 participant