feat: render inherited API class members from the parent doc - #1214
Draft
claude[bot] wants to merge 1 commit into
Draft
claude[bot] wants to merge 1 commit into
claude[bot] wants to merge 1 commit into
Conversation
Add a remark plugin (`src/transformers/api-inherited-members.ts`) that reads the `## Class: Child extends `Parent`` heading of an API doc, loads the sibling parent doc (`BaseWindow` -> `base-window.md`, walking the whole `extends` chain) and injects every member the child does not already declare into the matching section (Static Methods, Static Properties, Instance Events, Instance Properties, Instance Methods), with an "Inherited from" note linking to the parent page. Receivers and class names in injected headings are rewritten for the child. Members the child already documents are never injected, so pages that duplicate their parent today (BrowserWindow) keep every existing anchor and only gain the handful of BaseWindow members they never documented. WebContentsView and ImageView gain View's members. The plugin runs first in `beforeDefaultRemarkPlugins` so injected headings get ids and TOC entries and injected bodies go through the admonition, label, history and link transforms. Tests use the Node test runner (`yarn test`, also run in CI). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014dqqJFHsxFxatj9ZozxoT4
Deploying electron-website with
|
| Latest commit: |
601669a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://66ae85ec.electron-website.pages.dev |
| Branch Preview URL: | https://inherited-api-members.electron-website.pages.dev |
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.
Requested by Will Anderson · Slack thread
Description of Change
Before: A class page only shows what its own markdown file documents.
BrowserWindowlooks complete solely because electron/electron duplicates almost all ofBaseWindow's sections intobrowser-window.md(and still missescontentView,getContentView,setContentView, thepersisted-state-restoredevent and the staticclearPersistedState).WebContentsViewandImageViewsay they extendViewbut show none ofView's events, methods or properties.After: Pages render inherited members from the parent doc at build time. Each injected member keeps its heading, badges, history block and body, followed by an Inherited from
BaseWindownote linking to the parent page.BrowserWindow's anchors are unchanged (only the five members it never documented are added, and there are no-1slug suffixes).WebContentsViewandImageViewgainView'sbounds-changedevent,childrenproperty and nine instance methods, with the receiver rewritten where it differs (view.→image.on ImageView, including same-page anchors in the bodies).How: A new remark plugin,
src/transformers/api-inherited-members.ts, registered first inbeforeDefaultRemarkPlugins, parses the## Class: Child extends \Parent`heading, loads the sibling parent doc (BaseWindow→base-window.md, walking the wholeextendschain with a cycle guard;EventTargethas no doc and is skipped), and appends the members the child does not already declare to the matching depth-3 section (creating missing sections in canonical order) — so electron/electron can later drop the duplicatedBrowserWindowsections without a visible change on the site. Injected headings carry the classapi-inherited-member. Tests use the Node test runner (yarn test`, added to the PR workflow).Verification
node --test "src/**/*.spec.ts"— 18/18 pass, over the realdocs/latest/apifiles plus synthetic fixtures: BrowserWindow gains exactlyparent − childper section (today:Event: 'persisted-state-restored',BrowserWindow.clearPersistedState(name),win.contentView,win.setContentView(view),win.getContentView()), keeps every existing heading with no duplicates; WebContentsView gains everyViewmember appended after its own; ImageView receiver/anchor rewrite; WebSocket, a class withoutextends, and a doc outsideapi/are untouched; running twice is idempotent; grandparent chain, nearest-ancestor-wins, section ordering, history-block adjacency, link-definition carry-over and cycle guard.yarn lintcomponents:tsc --noEmit,oxfmt --check .,oxlint docusaurus.config.ts src scripts,markdownlint-cli2— all clean.yarn build(docusaurus build --locale en) and inspected the generated HTML:build/docs/latest/api/browser-window/index.html: 215 h3/h4 headings, 0 duplicate ids, 0 ids with a numeric suffix; the five injected h4s have idsevent-persisted-state-restored,browserwindowclearpersistedstatename,wincontentview,winsetcontentviewview,wingetcontentview, TOC entries (contentView,setContentView, …) and the note<em>Inherited from <a href=/docs/latest/api/base-window><code>BaseWindow</code></a></em>; the> [!NOTE]insidepersisted-state-restoredrenders as an admonition.build/docs/latest/api/web-contents-view/index.html: sections nownew WebContentsView,Instance Events(bounds-changed),Instance Properties(webContents, then inheritedchildrenwith itsReadonlybadge),Instance Methods(addChildView…getVisible); 11 injected headings, 11 notes, TOC entries for all, no duplicate ids.build/docs/latest/api/image-view/index.html: same members asimage.*; the body link toview.getBounds()now points to#imagegetbounds; ImageView's ownsetImagehistory table still renders.electronjs.orgis unreachable, so the releases plugin'sheaders/index.jsonfetch was stubbed locally (not committed) and the/fiddle/page failed to render for the same network reason; all docs pages were generated. None of the members injected on these pages has a history block or platform badge in the source, so that adjacency is covered by the synthetic test rather than the build.Open questions for reviewers
addChildView,setBounds, …" link list per section?api-inherited-memberclass, likeapi-options-class.tsdoes for option lists?browser-window.mdafterwards (render-time inheritance was proposed by nornagon in feat: replace BrowserView with WebContentsView electron#35658)? With this plugin that removal would be invisible on the site, but docs-parser/electron.d.tsconsumers would need their own handling.yarn startneeds a restart to pick up parent edits). Translated locales only inherit when the translated parent file exists.Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_014dqqJFHsxFxatj9ZozxoT4
Generated by Claude Code