twoslash
twoslash copied to clipboard
Handle errors spanning multiple tokens
This PR resolves #144 by creating a new function that checks whether each token is within the range of an error (e.character
to e.character + e.length
). Checking the range produces the correct results (T[Key]
is highlighted as an error):

This function replaces findTokenFunc
only when handling errors (lsp responses + queries still use findTokenFunc
).
I also added isTokenWithinErrorRangeDebug
which is similar to findTokenFuncDebug
for any future debugging needs.
🦋 Changeset detected
Latest commit: e501f8c955d4e800ca2206025beeb30e229e720c
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 9 packages
Name | Type |
---|---|
shiki-twoslash | Minor |
eleventy-plugin-shiki-twoslash | Patch |
markdown-it-shiki-twoslash | Patch |
remark-shiki-twoslash | Patch |
docusaurus-preset-shiki-twoslash | Patch |
gatsby-remark-shiki-twoslash | Patch |
hexo-shiki-twoslash | Patch |
twoslash-cli | Patch |
vuepress-plugin-shiki-twoslash | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
The accurateErrors
fixture from remark-shiki-twoslash
is failing, but I'm not entirely sure why. After removing all the noise, here's the diff:
- <data-lsp lsp='const todo: Readonly<Todo>' >todo</data-lsp>.<data-err><data-lsp lsp='(property) title: any' >title</data-lsp></data-err>
+ <data-lsp lsp='const todo: Readonly<Todo>' >todo</data-lsp>.<data-lsp lsp='(property) title: any' >title</data-lsp>
It shows that it's not rendering title
in todo.title = 'Hello'
as an error, but if I drop that fixture in a twoslash block in a local app using these these changes (with remark-shiki-twoslash
), title
is highlighted just fine:


Any ideas?
Oof, not sure when I'll find time to dig into this properly - this section of code is super gnarly and not an area I fully grok anymore