Repository navigation
docs(website): show the whole declaration in protocol docs code tabs - #1420
Open
SnowboardTechie wants to merge 3 commits into
Open
SnowboardTechie wants to merge 3 commits into
SnowboardTechie wants to merge 3 commits into
Conversation
Adds the lookup protocol pages will use to show a schema's code without file paths or line numbers. TypeSpec is read with the compiler's own parser; TypeScript with the TypeScript parser; Python with a small scanner that tracks brackets and strings. A name that isn't declared, or is declared more than once, throws.
Each protocol page now names the schema in <SchemaTable schema=...> and <SchemaFormatTabs schema=... typeSpec python typescript>, and the code tabs show the whole declaration found by name. About 100 tabs that were cut off, shifted or showing other code now show the right declaration, and a schema or snippet that can't be found fails the build. The schema-to-page map that links table types to their pages is built from the pages during the site build, so generate-schema-docs.ts goes, along with generate-schema-metadata.ts, generate-type-formatting.ts and SchemaMetadataLoader, whose output nothing read. Closes #872
Contributor
|
🚀 Website Preview Deployed! Preview your changes at: https://pr-1420-common-grants.agile6.workers.dev Built from commit f463bb1 |
… fields - The dev server re-reads the TypeSpec, Python and TypeScript sources once per page render, so a source edit shows on reload; a production build still reads them once. - Declarations shown together keep the blank lines the source has between them, so Python classes sit two blank lines apart. - The Python tabs for the pagination and sorting models show their base class (PaginatedBase, SortBase), which holds the inherited fields. - Drop code with no reader: the example file branch, the cache-clearing helper and an export; use the TypeSpec parser's line lookup and one shared recursive file listing.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes proposed
Protocol docs pages now find their code by schema name, so the TypeSpec, Python and TypeScript tabs show the whole declaration and can't drift when a source file is edited.
SystemMetadataTypeScript tab showedNameSchema, for example), one was empty, and the rest were shifted or cut off. All 240 now show the full declaration, with its doc comment and decorators in TypeSpec.<SchemaTable schema="Money" />and<SchemaFormatTabs schema="Money" typeSpec python typescript />. The 240startLine/endLinepairs are gone, and page frontmatter drops from 3,430 lines to 1,375. What's left is titles, the hand-written examples and the JSON Schemas written in the page for basic types likestringandurl, which have no generated file.PaginatedQueryParamssubclass a base (PaginatedBase,SortBase) that no page showed, so the tab was a class line and a docstring with no fields. Those tabs now show the base class above the class. This is the one place the pages change beyond repairing a snippet.generate-schema-metadata.tsandgenerate-type-formatting.tswrote output nothing read.generate-schema-docs.tsis replaced by building the schema-to-page map from the pages during the site build.generate-versioned-schemas.tsstays, because the Changelog sections link to the files it writes.Nothing under
lib/changes, and no page URL, heading, anchor or prose changes.Context for reviewers
The pages stay as MDX. The issue first proposed a catalog file and a dynamic route, and this comment explains why that was dropped.
Things worth a look:
website/src/lib/schema/source-declarations.tsis the new lookup. TypeSpec is parsed with the TypeSpec compiler's own parser and TypeScript with the TypeScript compiler API, both already dependencies. Python uses a small scanner that tracks brackets and strings. A name that isn't declared, or is declared more than once, throws.typeSpecorpythonlooks up the schema's own name, andtypescriptlooks up<Name>Schema. 23 tabs name their declaration explicitly because the SDK names it differently: the TypeScript enums end inEnum, the Python filter operator enums are singular, and a few type schemas use different capitals (ISODateSchema).typeSpec={["PaginatedBase", "Paginated"]}. Seven already showed a template or base model together with the model built from it, and each now shows both whole. The other six are the Python pagination and sorting tabs above. A tab shows only the declarations it names, so where other classes sit between the two in the file, they are left out and the source link spans from the first to the second.pnpm devre-reads the sources on each page load, so an edit to an SDK or TypeSpec file shows on reload. A production build reads them once.CommonGrants.Patchis skipped for bare names. That namespace inorganization-sync.tspredeclares twelve model names such asOrgIds, so a bare name means the one inCommonGrants.Models. A qualified name (Patch.OrgIds) still reaches the copy inCommonGrants.Patch.competition-versions.spec.tsread file paths out of the page frontmatter. It now reads theschemaandversionattributes and resolves them the way the components do. Each assertion keeps its meaning: the Form and Competition tables still come from the v0.5.0 schema files.Verified by building the site at
3a37f4efand again on this branch, then comparing all 51 protocol pages:NumberArrayFilterTypeSpec tab, which was empty because its line range ran past the end of the file.pnpm --filter website run cipasses: build, link validation, eslint, Prettier,tsc,astro check, cspell and 1,248 tests. Building with an unknown schema or snippet name exits 1.Additional information
Rendered pages: the website preview for this PR. Two pages that are wrong on the live site today, with their previews: date types, TypeScript tabs (live, preview), and award,
AwdIdsTypeSpec tab (live, preview).Every changed code tab, with its old and new line range (103: 92 changed code, 11 changed only the GitHub line link)