twoslashes / twoslash

Markup for generating rich type information in your documentations ahead of time.
https://twoslash.netlify.app/
MIT License
430 stars 16 forks source link

The "TwoSlash" protocol #17

Closed antfu closed 5 months ago

antfu commented 5 months ago

TwoSlash is great for TS code to display those types of information; it also provides a layer of pre-compiled information for tools like Shiki to consume. While TwoSlash is bound to the TypeScript language server, the generated information is actually not. This means that ppl could actually have different implementations to provide information in a similar data structure and reuse the infra that TwoSlash brings.

For example,

While I already made two slasher swappable in the Shiki transformer, I think it would be better if we provide a standardized type and interface to describe that information that can generally serve as an abstract layer for describing hover/error info from editors.

I imagine we could have a twoslash-protocol package or so that defines the types and provides some utilities like mapping the code positions, etc. So implementations like twoslash-rust and twoslash-eslint would deps on it without introducing typescript as deps at all.

WDYT? @orta