-
-
Notifications
You must be signed in to change notification settings - Fork 379
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
feat: store grammar state in weakmap #804
Conversation
✅ Deploy Preview for shiki-matsu ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for shiki-next ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #804 +/- ##
==========================================
- Coverage 94.92% 94.85% -0.08%
==========================================
Files 78 78
Lines 6504 6589 +85
Branches 1298 1317 +19
==========================================
+ Hits 6174 6250 +76
- Misses 321 330 +9
Partials 9 9 ☔ View full report in Codecov by Sentry. |
@antfu This seems to close #734 as well. |
Oh yeah, great to hear! |
In #712, we introduced GrammarState to resume the highlighting from the middle way. It solves the problem of customizing grammar context, but wasn't very useful for passable highlighting (for example, in a text editor, instead of highlighting the full context again over again, we can reuse the result from the previously highlighted lines) - because users need to run the parsing twice to get the
GrammarState
object. The existing API wasn't designed to be able to return extra property, making it hard to return theGrammarState
in one-go, without breaking changes.This PR overcharges the
shiki.getLastGrammarState()
function to be able to accept the return HastRoot
orThemedToken[][]
to retrieve theGrammarState
stored in a internal WeakMap. Make the usage more performent.Along the way, we also made
GrammarState
work with multiple themes by storing multiple internal state for each theme.The usage would be like:
close #803