Skip to content

feat(compiler): auto-generate reference url and surface docs on hover#11287

Open
tadelesh wants to merge 9 commits into
mainfrom
tadelesh/reference-docs-url-and-hover
Open

feat(compiler): auto-generate reference url and surface docs on hover#11287
tadelesh wants to merge 9 commits into
mainfrom
tadelesh/reference-docs-url-and-hover

Conversation

@tadelesh

Copy link
Copy Markdown
Member

Follow-up to #11221 (stacked on top of it). Builds on the tspd documentation generation to make the same docs available in the editor.

Note

Base is tadelesh/auto-gen-rule-diagnostic-docs (#11221). Review/merge that first; this PR's diff is just the url + hover delta.

Compiler

  • Auto-generated reference url. The library definition passed to createTypeSpecLibrary accepts referenceDocs.baseUrl. When set, the compiler auto-fills the url of any documented diagnostic/rule that does not specify one:

    • diagnostics -> ${baseUrl}/diagnostics/<code>
    • linter rules -> ${baseUrl}/rules/<name>

    This gives every documented diagnostic/rule a clickable code link in the editor without hardcoding a url per item, while avoiding links to pages that are not generated. An explicit url still takes precedence.

  • Language server hover. Hovering over a reported error now renders the extended docs of the corresponding diagnostic/rule as markdown, plus a "See documentation" link when a url is available. The LSP Diagnostic message is plain-text only (there is no markdown field on it), so hover is the only channel that can show rich docs inline at an error. Since emitter/linter diagnostics only exist in the full compile, the hover reuses the diagnostics from the last full compile — matched by source location the same way the squiggles are — and resolves each one's docs through a new @internal Program.getLoadedLibraryInfo that loads the library's default entry via the compiler's own (cached) entrypoint loader. That default entry is where the linter export lives, whereas the entry .tsp files import (the typespec condition) may only expose the library definition.

Pilots

  • @typespec/http — the op-reference-container-route rule declares referenceDocs.baseUrl and drops its hardcoded url (now auto-generated).
  • @typespec/openapi3 — declares referenceDocs.baseUrl so its 6 documented diagnostics get auto-generated urls.
  • Both packages now publish their src/**/*.md so installed libraries can resolve FileRef docs at runtime (used by the hover).

Validation

  • Built compiler, http, openapi3; the compiler server suite (including the URL and hover tests) and the op-reference-container-route rule tests pass.

tadelesh and others added 9 commits July 13, 2026 10:53
Add an optional docs field (raw markdown, loaded from a co-located .md file) to linter rule (createRule) and diagnostic (createTypeSpecLibrary) definitions. tspd renders a page per rule (reference/rules/<name>.md) and per diagnostic (reference/diagnostics/<code>.md) plus a diagnostics index, and reports documentation-missing for undocumented rules/diagnostics. Migrates @typespec/http op-reference-container-route and @typespec/openapi3 path-query as pilots.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address review feedback:
- Add a docs field (string | FileRef) to linter rule and diagnostic
  definitions in the compiler; docs are read lazily by tspd so definitions
  stay browser-bundle safe.
- Always report documentation-missing for any linter rule or diagnostic
  without docs, instead of gating the check.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ules

Add a referenceDocs.baseUrl field to the library definition. When set, the
compiler auto-fills the url of each diagnostic and linter rule that does not
specify one explicitly (diagnostics -> <base>/diagnostics/<code>, rules ->
<base>/rules/<name>), so the editor and CLI get a documentation link without
hardcoding a url per item. Migrate @typespec/http and @typespec/openapi3 to
declare referenceDocs and drop the hardcoded rule url.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…e server

When hovering over a reported error, the language server now renders the
extended documentation of the corresponding diagnostic or linter rule (its
docs field, inline markdown or a FileRef read lazily) together with a link to
the generated reference page when a documentation url is available.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…e-diagnostic-docs

# Conflicts:
#	packages/compiler/test/server/get-hover.test.ts
Publish FileRef markdown assets and avoid generating reference links for
undocumented diagnostics/rules. On hover, reuse the diagnostics from the last
full compile (matched by source location the same way squiggles are) to show
the extended documentation of the diagnostic/rule under the cursor, resolved
by reusing the library already loaded by the compiler instead of re-resolving
and reloading it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: de8537de-5e61-4a0d-b2de-59ec12c15dc4
…ver into a follow-up PR

This PR now only contains the tspd documentation generation (the \docs\ field
+ \FileRef\, and tspd rendering a page per rule/diagnostic). The
\
eferenceDocs.baseUrl\ url auto-generation and the language server hover that
surfaces the docs are moved to a separate PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: de8537de-5e61-4a0d-b2de-59ec12c15dc4
Builds on the tspd documentation generation. Add `referenceDocs.baseUrl` to the
library definition so the compiler auto-fills the `url` of documented
diagnostics/rules that don't set one (an explicit url still wins), and make the
language server render a diagnostic/rule's `docs` (plus a documentation link)
when hovering over a reported error, resolving the library via a new `@internal`
Program.getLoadedLibraryInfo.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: de8537de-5e61-4a0d-b2de-59ec12c15dc4
@microsoft-github-policy-service microsoft-github-policy-service Bot added compiler:core Issues for @typespec/compiler lib:http tspd Issues for the tspd tool emitter:openapi3 Issues for @typespec/openapi3 emitter labels Jul 17, 2026
Base automatically changed from tadelesh/auto-gen-rule-diagnostic-docs to main July 20, 2026 14:50
@microsoft-github-policy-service microsoft-github-policy-service Bot added the meta:website TypeSpec.io updates label Jul 20, 2026
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 emitter:openapi3 Issues for @typespec/openapi3 emitter lib:http meta:website TypeSpec.io updates tspd Issues for the tspd tool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant