chomosuke / typst-preview.nvim

Low latency typst preview for Neovim
GNU General Public License v3.0
254 stars 16 forks source link

Preview stops updating on typing for large enough files #19

Closed AxiomOfChoices closed 7 months ago

AxiomOfChoices commented 7 months ago

I have been writing course notes for myself and a few days ago I noticed that the preview stopped updating when I was typing, and only updated when I saved the file.

I managed to recreate a simple test case, create a new file named preview_test.typ, and add in 10905 lines of the word "Test". Removing lines in this file still shows up in the preview with no issues, but now adding a 10906th line with the word "Test" breaks the preview, it stops updating completely.

I am not sure if this is an issue with the neovim plugin specifically or with the upstream server, could even be an issue with typst.ts. I'll keep testing to see if I can get more info. So far I only know that comments do seem to count towards the size 'threshold' and that threshold is suspiciously close to 2^16 Bytes.

AxiomOfChoices commented 7 months ago

It seems that this issue does not occur with the same file using vscode and the typst-preview extension, so it seems like vim stops updating buffer content on type for large enough files.

AxiomOfChoices commented 7 months ago

Managed to track down the source of the issue, when JSON encoded file length passes 2^16 bytes, it passes the default buffer size for websocat, this makes websocat split it into 2 lines which breaks the typst-preview server.

As a work around, adding '-B 10000000' to the arguments of websocat moves the threshold to a source file of size 10MB which is a lot harder to reach. If I recall correctly from my OS classes, large buffers like this are non-ideal, but I think the alternative is reworking the source code for the typst-preview server to accept multi-message file updates. This seems like too much effort for just this edge case.