-
Notifications
You must be signed in to change notification settings - Fork 54
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
Support for multiple languages #149
Comments
Well, this is very impressive, having other languages conform to the twoslash API shape is a clever idea! (It's very similar to how I built multi-langauge support into Danger JS. I'm semi hesitant on the idea of supporting multiple languages not because it's a bad concept, but because of how much the docs and my ease of maintenance is tied to it being 1 platform which I understand very deeply (and used to be able to put full-time effort into.) That said, having a non-hostile fork for this would also be a weird concept (a lot of the hard work of setting up the HTML is done and hasn't changed in a long time (excluding #145)) but I'm wary of rust and other languages feeling like a 2nd class citizen when this is so cool and should have the chance to shine properly. I had recommended someone take the ideas of twoslash to create an LSIF version #110 but I can't help but feel like allowing LSIF inputs is also a direction we should take it shiki-twoslash. I think it's now quite difficult to make changes to the underlaying twoslash lib (because I don't have write access to that repo anymore) but TypeScript doesn't conform to LSP anyway, having it as an exception seems OK (we could add code in here which goes from the ts implementation to a more standard feeling one) So, things worth thinking about before we commit:
( Sorry for such long-term thinking on a prototype but I intend to be maintaining this for many years and this is probably the biggest idea that'd be added to the project since its launch ) |
I agree with you, there is a ton of value in the rendering portion (which is the novel and interesting bit) and I think it would be really nice to reuse the work you've already done to generate annotations for any language semantics. Thank you for taking the time to note your ideas and concerns; I agree with all of them. With them in mind, I think a plugin model along the lines I proposed in the original comment would work well to alleviate them. In greater detail:
One perspective is that shiki-twoslash is a rendering engine for static code information - indeed that is already what it is, it just happens to be specialized for the TS/JS use case. But the library itself does not do semantic analysis over TS/JS; @typescript/twoslash does that. So, by providing a mechanism to insert custom semantic analyzers for other languages, shiki-twoslash can continue to avoid having to care too much about what languages there are, and instead say "okay, just give me an opaque function by which I can produce analysis information, and I'll render something nice for you". So I don't think this model changes too much. Indeed you can see the diff of my current fork - it's not large.
Yes. The current tool I have demands that you put a binary to produce the rust code analysis (this one) somewhere in your PATH and install a JS model that links against it, but then you're off to the races. Importantly, with the model I am proposing here (which is not the one currently implemented in my fork), shiki-twoslash does not need to worry about the ergonomics of the language-plugins. shiki-twoslash would only have to detect what language a piece of code is, and pass that code to the appropriate plugin, so the usability experience is the concern of the plugin. Of course then there is the problem of setting a standard for high-quality plugins, but I don't think that's actually so hard.
I think it would make sense to give an introduction and say "also, you can use these N other plugins for different languages!" but expect that the plugins have more thorough usage documentation. Again, this enforces shiki-twoslash being the rendering engine rather than the semantic analysis tool.
This is a really good question. I could see arguments both ways. Maybe the cop-out answer is to say the syntax is plugin-defined, but of course it's good to have some cohesion. I don't know. Maybe there is a requirement that |
Here from #49 and happy to pitch in too ⋔ |
Hey Orta, would have any interest in extending this library to support generation for multiple languages?
I recently added support for Rust to this library in a local fork (here is the patched branch and the Rust library generating a
TwoSlashResult
). It indeed works - here's an example screenshot (I'll replace with a real URL when I can share it widely, EDIT: here's the live example):My current implementation is a bit hacky, but before I do more work to improve it I'd like to gauge whether this is kind of use case is something you'd be interested in accepting patches for. If indeed you are interested in this, I think the following model would make sense:
(code: string, extension: string, options: unknown) => TwoSlashReturn
that should be run over code blocks with certain language fences.TwoSlashReturn
to better fit formats that can be returned by any LSP server, for example something more similar to LSIF. I don't think this is as big of a deal as the above point, because the current interface is easy-enough to marshal into.Let me know what you think!
Related to #110
The text was updated successfully, but these errors were encountered: