MyST editing catalog#

The Sublime plugin and language server can use myform.myst_catalog for directive and role names, documentation, and option suggestions. Editing commands use the same metadata to recognize bodies that have their own grammar.

from myform.myst_catalog import load_catalog

catalog = load_catalog(["sphinx.ext.autodoc"])
assert catalog.is_raw_directive("toctree")
assert catalog.directives["autoclass"].arguments.required == 1
assert catalog.roles["ref"].summary

for option in catalog.available_options("note", used=["name"]):
    print(option.name, option.values)

A catalog’s directives and roles mappings list suggestions for the built-in and selected extensions. directive(name) and role(name) also resolve known spellings from unlisted extensions. Their extension fields give the owner for hints, which a caller can check against catalog.extensions. Unknown entries return None, and unknown directive bodies stay editable.

Pass extension IDs from the consumer’s myst-extensions setting. workspace-extensions still controls which filename suffixes the server indexes. Catalog loading reads bundled metadata and treats IDs as strings. Workspace Python, conf.py, and extension modules are never executed.

Maintaining the data#

myform/_myst_catalog_data.py contains the metadata distributed in the wheel and source distribution. Its source snapshot is Docutils 0.22.4, Sphinx 9.1.0, and MyST Parser 5.0.0. Check keyword spellings and option converters in the upstream directive’s option_spec. For arguments, compare the class’s required_arguments, optional_arguments, and final_argument_whitespace. Mark an option required only if its key must be present. Docutils’ unchanged_required converter requires a value when the key is supplied. Enter each key as its own string in _options(...) so wrapping the source preserves the spelling.

  • Docutils provides the English base directive and role names. See docutils/parsers/rst/languages/en.py and docutils/parsers/rst/directives.

  • Sphinx patches standard directives and provides its own directive, role, and domain names. See sphinx/directives, sphinx/roles.py, sphinx/domains, and sphinx/ext/autodoc/_directive_options.py in the installed sources.

  • MyST adds figure-md and sub-ref in myst_parser/sphinx_ext/directives.py. Its renderer in myst_parser/mdit_to_docutils/base.py handles eval-rst and adds options to include.

  • Fleet extension owners come from the repositories’ Sphinx configurations: sphinx.ext.autodoc in docs/conf.py, and the sic role in the lit repository’s docs/_ext/sic.py. Intersphinx and Napoleon have no fixed names in the catalog. Intersphinx’s external role suffixes depend on domain registrations and workspace inventory names.

  • The optional sphinxcontrib.bibtex entries support the plan’s citation roles. Their syntax comes from the extension’s usage reference and directive source.

For a new entry, record its owner, name, summary, and actual option or argument grammar. Check how the directive handles body lines before setting raw_body. For example, Sphinx parses acks as a list of Markdown items and toctree as one path entry per line. The catalog also keeps the legacy source-code spelling inert for editing. Sphinx’s registered spelling is sourcecode.

Add a test for the new metadata in tests/test_myst_catalog.py. tests/smoke_package.py checks that the metadata and API are available from the installed release artifacts.