zed
zed copied to clipboard
support for Typst language
Check for existing issues
- [X] Completed
Describe the feature
Support for the Typst language (to replace LaTeX): https://github.com/typst/typst, with instant preview, like in the VSCode plugin: https://marketplace.visualstudio.com/items?itemName=mgt19937.typst-preview
The Typst compiler is written in rust, so it could be a nice integration.
If applicable, add mockups / screenshots to help present your vision of the feature
No response
There's already an extension which should already be available in Zed (which uses tinymist, which seems more active and with more features than typst-lsp). I previously tried to make one based on typst-lsp before extensions had lsp support: #9152 but it's a lot worse than WeetHet's one. Pdf preview is quite hard to do, I had a discussion on possible ways to implement it here (the vscode extension uses pdf.js but Zed currently doesn't have for support webviews), to summarize it:
-
macOS: https://developer.apple.com/documentation/pdfkit
-
windows: https://learn.microsoft.com/en-us/windows/win32/api/windows.data.pdf.interop/
-
linux: it's complicated, libpoppler seems to be the best option, we can either:
- Invoke one of the
pdfto*
binaries it ships with - Use
libloading
to dynamically load it and use an unsafe api - Use
poppler-rs
and have poppler as a hard dependency
- Invoke one of the
But I just found out that typst has png and svg support which would be a lot easier to implement (doesn't replace the need for pdf support, but is a good workaround). The issue is that extensions currently can't really run code other than tree-sitter grammars/lsp, and this would need a custom view, so it's blocked on more extension support: #5269
Thank you for your answer! Indeed using a web view would make this extension very easy to implement using e.g. https://github.com/Myriad-Dreamin/typst.ts.
The PNG idea is good, I tried typst watch test.typ test.png
which compiles on save, but unfortunately the PNG does not update in zed (https://github.com/zed-industries/zed/issues/11529)
If/when webviews are implemented I don't even think typst.ts is necessary, we can just run the normal typst binary in watch mode and have pdf implemented with webviews separately. I'll try to work on implementing refreshing in image views, I completely overthought it with the custom view thing, I forgot you can just... view pngs 😅