Myriad-Dreamin / tinymist

Tinymist [ˈtaɪni mɪst] is an integrated language service for Typst [taɪpst].
https://myriad-dreamin.github.io/tinymist
Apache License 2.0
267 stars 11 forks source link

Preview through LSP #357

Open knuesel opened 3 days ago

knuesel commented 3 days ago

Motivation

Making "onType" browser preview and jump-to-source work in Helix and other editors that don't support VS Code extensions.

Currently I use https://github.com/tmistele/typst-lsp: a fork of typst-lsp that opens its own window to draw the preview, and also uses LSP to jump in the source when clicking somewhere in the preview. But it's rather experimental, the GUI is not very functional and it's not actively developed.

Description

Examples/Questions

I think it would make sense to have these settings separate from exportPdf (I would like to use both the live preview in the browser and compile to PDF on save).

Question: should this be implemented in the tinymist server, or as a new minimal LSP server just for preview? I guess in the tinymist server would be easier to use for most people. On the other hand a minimal LSP server would be nicer for those who only want the preview.

Myriad-Dreamin commented 3 days ago

Separating preview thread and LSP thread in different processes will double the memory usage on compilation. Tinymist has already integrated typst-preview since v0.11.12, which hasn't been used yet though.

To test it, you can check:

cargo run --bin tinymist -- preview main.typ

For minimal LSP, we can do some LSP wrapping on the preview server rather than publishing another binary. Some idea on server mode:

Note: we are encountering some bug in v0.11.12. If you are still on v0.11.11, please wait for v0.11.13 to have a stable release that fixes this bug.

knuesel commented 3 days ago

I managed to preview a file with cargo run --bin tinymist -- preview main.typ but it doesn't seem to work as an LSP server for helix. I guess that's expected?

Your ideas for minimal LSP sound great :)