-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
feat(shiki): add twoslash support #8132
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
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #8132 +/- ##
==========================================
- Coverage 76.59% 76.41% -0.19%
==========================================
Files 115 115
Lines 9602 9621 +19
Branches 322 316 -6
==========================================
- Hits 7355 7352 -3
- Misses 2246 2268 +22
Partials 1 1 ☔ View full report in Codecov by Sentry. |
Hype 😁 ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds TypeScript TwoSlash support to the syntax highlighting system, enabling interactive TypeScript error displays and type information tooltips in code blocks.
Key Changes:
- Integrated TwoSlash transformer for TypeScript/JavaScript code highlighting
- Refactored metadata parsing system from string-based to object-based approach
- Added CSS styling for TwoSlash popup containers and error displays
Reviewed Changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
packages/rehype-shiki/src/index.mjs | Added TwoSlash transformer import and configuration |
packages/rehype-shiki/src/highlighter.mjs | Updated functions to accept metadata parameter and pass transformers |
packages/rehype-shiki/src/plugin.mjs | Replaced string-based metadata parsing with comprehensive object-based system |
packages/rehype-shiki/src/twoslash.css | Added CSS styling for TwoSlash popup containers |
packages/rehype-shiki/package.json | Added TwoSlash dependency and exported CSS file |
packages/ui-components/src/Common/BaseCodeBox/index.module.css | Added CSS transforms for proper positioning |
apps/site/next.config.mjs | Configured external packages and file tracing for TwoSlash |
apps/site/package.json | Added twoslash dependency |
apps/site/styles/index.css | Imported TwoSlash CSS styles |
apps/site/pages/en/learn/typescript/transpile.md | Updated TypeScript example to use TwoSlash error annotations |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Is this all server side? I'm asking because given the TS port to Go, I'm not sure what the deal will be for shiki on the web; probably having to include a large Go binary in Wasm to work with all of the fancy stuff if not prerendered... |
All server-side, yes. We don't pass the complicated WASM binaries and Shiki configurations to the client. The client gets a basic syntax highlighter w/ Shiki's RegEx engine. |
@dario-piotrowicz Does this setup not support OpenNext? If not, we can make it conditional, like we do for the WASM engine |
@AugustinMauroy fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow soo cool
@@ -88,31 +89,4 @@ const justine: User = { | |||
const isJustineAnAdult: string = isAdult(justine, "I shouldn't be here!"); | |||
``` | |||
|
|||
And this is what TypeScript has to say about this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of useful because it's the output that the reader/user will see in this terminal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file is minimified during publish process ?
Also should add docs somewhere about why here we don't use tailwind.
It's not supposed to be passed to the client at all, so we should definitely investigate that |
Fixed in the latest commit, which introduced some styling issues (regarding wrapping). |
Fixes #7932
Introduces
@shikijs/twoslash
support in@node-core/rehype-shiki
. Sincetwoslash
depends on TypeScript declaration files, it cannot be bundled and must instead be listed underserverExternalPackages
.Because TypeScript declarations aren’t imported like regular files (they’re loaded through a TSVFS), they need to be explicitly included in the output bundle.
Because Cloudflare doesn't support WASM or Top-Level awaits, rehype-shiki has been rewritten to not rely on them.