-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
TypeScript-powered Code Blocks #120
Comments
Bikeshed: There are a bunch of ways in which embedded the complier metadata @andrewbranch's JSON after language
and prefixed HTML comments (maybe with YML?)
@RyanCavanaugh's fourslash inspired inline comments:
My re-use of Jekyll-style which embed yml at the top of a code block:
|
One thing that Andrew's blog does is that it allows for typescript files to to work across code samples, e.g.
Where at build time |
In addition to passing compiler flags as comments, it would be great to also be able to control the tsc version. This would help for tsc bug reporting and easing comms around tsc behaviour change over time. |
Something that might help with getting the hover tooltip: We have tsserver exposed over WebSockets at wss://typescript.sourcegraph.com. It speaks the Language Server Protocol, and can accept arbitrary For the UI part of this - the library that renders the hover tooltips on sourcegraph.com and in our browser extension is stand-alone and open source: https://github.com/sourcegraph/codeintellify (I always hoped one day it would be useful exactly for open source documentation snippets!) |
What a great idea @felixfbecker! if this were not for the TypeScript website primarily, I'd definitely be into that - we'll probably need a bunch of weird features like the above. ❤️ |
A few random thoughts:
For (i), the answer is mostly the compiler API, but there are other providers you’ll need to get data from too—syntax highlighting isn’t going to come from the compiler (I tried it once; it doesn’t give good results), and line or span highlighting is going to be some kind of separate annotation. So for (ii), even if you want to use LSIF for part of this, you’ll probably need to embed the LSIF data within a top-level data structure that also holds syntax highlighting and other auxiliary data. Then (iii) is just a fun UI-building problem. I should also mention that gatsby-remark-vscode is (appropriately) only designed to work within the Gatsby stack, and currently it only outputs HTML, essentially robbing you of the opportunity to do steps (ii) and (iii) yourself. I’m in the process of allowing users to query GraphQL for its tokenization results, which would let you compose its info with other data sources (ii) and render it all however you want (iii). But, if you’d rather work with something lower level or not gatsby-specific, but higher level than vscode-textmate, you could try shiki. |
Something I'd also like is for a bot to show up on GitHub issues and show the typechecking/emit results of any code blocks in the OP, along with a short version history (e.g. "This behavior is unchanged since version 3.1") |
@orta do you mean specifying the compiler options? I think that can work like this:
But if you can/want to precompute this data, that makes sense, and there would be no need to involve language servers then. @andrewbranch since I've used LSIF and LSP a lot, maybe I can answer some of the questions: LSIF is probably a good bet (and is just JSON). Both LSIF and LSP use the I'm happy to answer any other questions or share my knowledge here if it's helpful - I think having hover tooltips in docs would be an amazing way to show how what makes TypeScript great! |
@felixfbecker - yeah, I want to pre-compute everything on the site, and it's not definitely not outside the realm of possibility that we'll want to run this sort of code against betas and PR builds also (like we do for the playground) - so having it all live in the build process is pretty much a must for me @RyanCavanaugh @andrewbranch Yeah - thanks, I think this can be split into a multi-step process then:
Each of these move it forwards |
There's been quite a lot of progress on this:
|
This is for all intents and purposes, done and the modules are shipped to npm |
Things I want for all code blocks inside website v2:
Sidegoal:
Make this not directly tied to the website so that anyone with a Gatsby blog can re-use this for their own docs with very little setup.
Places with existing infra this can build from:
orta/lsif-tsc-remark-example
- an example of using the LSIF format (static language server protocol) to extract metadata. Overall, I think it's too much to go through the entire tsc-lsif, we could probably just steal the syntax for hover tokens and diagnostics and call it enough maybe.microsoft/TypeScript-New-Handbook
the handbook has a good set of existing examples for this, these could be re-formatted into Gatsby/remark plugins.andrewbranch/gatsby-remark-vscode
re-using VSCode at build time to handle the syntax highlighting.andrewbranch/blog
- uses the typescript API to inline annotate embedded TypeScript ( long form on how it works )/cc @andrewbranch @RyanCavanaugh
The text was updated successfully, but these errors were encountered: