Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript Documentation: Improve the JS API documentation tool. #61036

Open
youknowriad opened this issue Apr 24, 2024 · 6 comments
Open

JavaScript Documentation: Improve the JS API documentation tool. #61036

youknowriad opened this issue Apr 24, 2024 · 6 comments
Labels
[Type] Developer Documentation Documentation for developers [Type] Enhancement A suggestion for improvement.

Comments

@youknowriad
Copy link
Contributor

youknowriad commented Apr 24, 2024

What problem does this address?

In Gutenberg we use a custom made tool called api-docs to parse the exported JS APIs and document them in the README files of each package and end up in a package in the block editor handbook (useSelect Example).

This is not very different from how the WordPress PHP APIs are extracted and documented on the developer docs.

But there are some subtle differences that make a big difference in terms of results:

  • For the PHP APIs, each API has a dedicated page while the JS APIs are all in the same page and some packages have a big list of APIs impacting the reading and sharing experience.
  • It is possible for users to comment on PHP API docs to share examples and clarify some important but maybe subtle things.
  • I believe it WordPress documentation contributors have the possibility to augment the generated docs (from the code) and complete the information.

What is your proposed solution?

  • Consider extracting each JS API to its own dedicated markdown in the handbook (We need to check whether to gitignore these or not). Each markdown file can become a dedicated package on the handbook by adding it to the manifest.json file.
  • Consider enabling comments on each of these generated pages. (Probably requires a meta ticket). We already have dedicated pages for components in the handbook, so we may be able to explore this even without changing the output of the existing JS docs.
  • Consider whether it's possible to provide a way for contributors to "augment" the generated markdown with a manually written markdown file for each JS API.

I also believe that some of our JS Docs are not great but having dedicated pages for each API will incentivize developers and documentation contributors to actually submit PRs and improve these. Today, these are hidden within a huge README file.

cc @oandregal @tomjn

@youknowriad youknowriad added [Type] Enhancement A suggestion for improvement. [Type] Developer Documentation Documentation for developers labels Apr 24, 2024
@tomjn
Copy link
Contributor

tomjn commented Apr 24, 2024

Given that we already have designs and templates for the PHP equivalent and post types, does it make sense to reinvent that for this? It seems counter intuitive that there be 2 separate code references on the devhub with differing capabilities.

E.g. the existing code reference can tell me a function was introduced in WP 6.5, likewise it'd be useful to see both PHP and JS functions/hooks when debugging:

Screenshot 2024-04-24 at 10 30 03

This code reference is also plumbed into some existing tools so there'd be synergies

@oandregal
Copy link
Member

cc @juanmaguitar for awareness, as we talked about this the other day.

Ideally, we should aim to incorporate the JavaScript APIs to The Reference, that only contains PHP for now. The Reference provides a lot more (focused search, list changes by WordPress version, etc.) and is the centralized place for this kind of thing. This track ticket contains references to past efforts https://meta.trac.wordpress.org/ticket/3063

For context, there are two pieces at work here:

  • docgen: this tool generates markdown from the JSDoc comments of the exported entities in a given entry point. This is Gutenberg agnostic.
  • api-docs scripts: these are specific to our repo. For example, the update-api-docs.js takes the README.md files of our packages and searchs for a given pattern (<!-- START TOKEN( and <!-- END TOKEN(). Anything in between those tags is substituted by the Markdown generated by docgen for that package.

@youknowriad
Copy link
Contributor Author

For clarity, I'm not really opinionated on how we implement this. The only requirement I have technically is that the code base and the documentation stay together (in the code base), how it's generated and published is implementation detail.

@tomjn
Copy link
Contributor

tomjn commented Apr 24, 2024

Would it help to have a minimum scope for what a single page for an item would contain? As well as what we intend it to apply to? E.g. components have been mentioned but does it make sense to include packages given they sort of already have that in the handbook?

@juanmaguitar
Copy link
Contributor

juanmaguitar commented May 12, 2024

I have been discussing this issue with @oandregal, and we concluded that the following actions could make a good plan of action to move this issue forward:

This work would affect code at the following repos:

  • gutenberg - for the custom output of the parsed JSDoc info
  • wporg-developer-2023 theme - for the custom taxonomies registration
  • phpdoc-parser plugin - for inserting the custom JSON and adapt the code so this extra functions are properly inserted as CPT with their proper taxonomies

This plan would enable the same functionality for JavaScript (JS) functions available for PHP functions at https://developer.wordpress.org/reference/functions. It would also allow for distinguishing between JS functions and PHP functions.

After this first milestone, we could expand the functionality of this process to also include relationships between JS functions in the same way we have them for PHP functions.

@dmsnell
Copy link
Member

dmsnell commented Jul 3, 2024

At WCEU @juanmaguitar and @adamziel and I discussed calling out to the TypeScript language server from the phpdoc-parser process where the Gutenberg source code is symlinked or otherwise available in the WordPress installation.

This would allow the PHP code to generate the docs from the JS files and make a clean integration - the JS process wouldn't have to match formats, the would be no JS side to this at all.

Language server calls are XML-RPC calls over HTTP so shouldn't be a technical obstacle on the PHP side. We can iterate over all the files, get all the symbols, get all the docblocks attached to them, and get the inferred types whether JS or TS.

I think this is a valuable avenue to explore as it collapses a lot of complexity into a project that already understands the Gutenberg codebase enough to provide IDE inline documentation, jumping, and autocomplete - the TypeScript Language Server.

As discussed this has interesting tie-ins to using php itself with ReflectionClass/ReflectionFunction/etc… introspection which could eliminate the need to depend on nikic/php-parser and provide more knowledge than we currently have, such as resolved namespaces. (A remaining problem dependent on the parser would be inferring filter variable placeholders).

Just wanted to leave the notes so this doesn't get lost as I think it's a viable path to explore to improve our docs generation and simplify it at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Developer Documentation Documentation for developers [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

5 participants