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

Handle errors spanning multiple tokens #145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

with-heart
Copy link
Contributor

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):

image

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-bot
Copy link

changeset-bot bot commented Mar 4, 2022

🦋 Changeset detected

Latest commit: e501f8c

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

@with-heart with-heart force-pushed the handle-errors-spanning-multiple-tokens branch from 3940997 to e501f8c Compare March 4, 2022 20:56
@with-heart
Copy link
Contributor Author

with-heart commented Mar 4, 2022

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&lt;Todo>' >todo</data-lsp>.<data-err><data-lsp lsp='(property) title: any' >title</data-lsp></data-err>
+ <data-lsp lsp='const todo: Readonly&lt;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:

image

image

Any ideas?

@orta
Copy link
Contributor

orta commented Mar 7, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

twoslash renderer not highlighting errors that span multiple tokens
2 participants