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

Support remark/rehype/recma transformer plugins #297

Open
4 tasks done
remcohaszing opened this issue Feb 4, 2023 · 1 comment
Open
4 tasks done

Support remark/rehype/recma transformer plugins #297

remcohaszing opened this issue Feb 4, 2023 · 1 comment
Labels
🗄 area/interface This affects the public interface help wanted 🙏 This could use your insight or help 🙉 open/needs-info This needs some more info 🤞 phase/open Post is being triaged manually 🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have

Comments

@remcohaszing
Copy link
Member

Initial checklist

Problem

Currentle the language service only supports unified plugins that register micromark syntax extensions. It doesn’t support transformer plugins yet.

For example, remark-mdx-frontmatter, rehype-mdx-title, and recma-nextjs-static-props provide a transformers that injects ESM exports into the AST.

Solution

TypeScript needs to be aware of injected variables and their types. I don’t know how yet.

Alternatives

🤷

@remcohaszing remcohaszing added 🦋 type/enhancement This is great to have help wanted 🙏 This could use your insight or help 🗄 area/interface This affects the public interface 🧒 semver/minor This is backwards-compatible change 🙉 open/needs-info This needs some more info 🤞 phase/open Post is being triaged manually labels Feb 4, 2023
@remcohaszing
Copy link
Member Author

I have some vague ideas, but none of these are ideal.

Firstly, let’s determine what it means for IntelliSense to apply a transformer.

Transformers can:

  1. Inject module level exports, which become available everywhere. (rehype-mdx-title, remark-mdx-frontmatter)
  2. Inject variables into _createMdxContent, which become available inside JSX and expressions.
  3. Give meaning to custom constructs (rehype-mdx-code-props, remark-mdx-math-enhanced).

Most transformers transform the hast in ways that doesn’t affect the editor experience. For example remark-toc injects a table of contents, but that doesn’t introduce variables nor remove anything relevant.

Some potential solutions:

  1. If custom plugins are defined, we can run all plugins, compiling to ESTree. We can then detect generated variable declarations and insert them into the virtual code.
    • Maybe we could even support expressions and JSX expressions if they have positional data and for example their value is an empty string?
    • Types now depends entirely on inference.
  2. Plugins could have a custom entrypoint for MDX analyzer, then use a special API to resolve types.
    • We need to define what that API is.
    • Custom logic is needed for a plugin to support IntelliSense.
    • Plugins have control to make types more specific.
  3. Add hardcoded support for a selective list of plugins.
    • Probably best support for these specific plugins.
    • Not pluggable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface help wanted 🙏 This could use your insight or help 🙉 open/needs-info This needs some more info 🤞 phase/open Post is being triaged manually 🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have
Development

No branches or pull requests

1 participant