Skip to content

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

Open
tadelesh wants to merge 1 commit into
tadelesh/auto-gen-rule-diagnostic-docsfrom
tadelesh/reference-docs-url-and-hover
Open

feat(compiler): auto-generate reference url and surface docs on hover#11287
tadelesh wants to merge 1 commit into
tadelesh/auto-gen-rule-diagnostic-docsfrom
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.

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
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 tspd Issues for the tspd tool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant