twoslash icon indicating copy to clipboard operation
twoslash copied to clipboard

`tsconfigJSONRenderer` fails on themes which render the surrounding quotes as separate tokens

Open cspotcode opened this issue 2 years ago • 2 comments

When tsconfigJSONRenderer checks if a token is a known tsconfig property, it assumes the token starts and ends with double-quotes. However, on themes where the surrounding quotes are rendered in a different color, they are different tokens.

This logic ends up removing the first and last characters, so for example, instead of checking baseUrl, it checks aseUr.

https://github.com/shikijs/twoslash/blob/8054fff138aa7a253aed3582a89e7ffc4ed28b96/packages/shiki-twoslash/src/renderers/tsconfig.ts#L17

I guess the fix is to detect if quotes are or are not included in the token and behave accordingly.


On the topic, I was wondering if anyone tried implementing JSON schema-powered tooltips. Naively, I assume VSCode gets its JSON schema-powered tooltips from an LSP similar to TS, so I wonder if it could be consulted to provide twoslash-style tooltips but for JSON documents. Do you know, has that been attempted, and is there anywhere I should go to read more?

cspotcode avatar Mar 03 '22 03:03 cspotcode

Looks like the schema-based tooltips could be generated using https://github.com/microsoft/vscode-json-languageservice

If that seems like an interesting idea, I can extract it to a separate issue.

cspotcode avatar Mar 03 '22 04:03 cspotcode

Yep, that's a great solution for a general JSON schema hovers - I'd like to keep the twoslash tsconfig one short simple and focused, but I have no problem having a way to replace the tsconfig renderer with something more complex!

orta avatar Mar 03 '22 09:03 orta