Skip to content
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

Live preview for simple editors like helix #722

Open
knuesel opened this issue Oct 22, 2024 · 6 comments · May be fixed by #1142
Open

Live preview for simple editors like helix #722

knuesel opened this issue Oct 22, 2024 · 6 comments · May be fixed by #1142
Labels
editor-integration Features about editor integrations enhancement New feature or request

Comments

@knuesel
Copy link

knuesel commented Oct 22, 2024

Motivation

Having instant preview work in Helix.

Description

The live preview would be configured from the Helix side using the initialize request. I guess this could work similarly to how it works in this fork of typst-lsp: https://github.com/tmistele/typst-lsp

(This feature is a follow-up of #357 to discuss specifically the support for editors like Helix that have limited LSP support.)

@Myriad-Dreamin Myriad-Dreamin added the enhancement New feature or request label Oct 22, 2024
@TheZoq2
Copy link

TheZoq2 commented Nov 15, 2024

I came up with a hack to get this feature working before helix supports custom lsp commands:

We can have a small proxy between helix and tinymist which inserts the preview commands into the LSP. For now I made a proof of concept that can start and view the preview, but forward/backward sync is not available. I'll probably look at that tomorrow.

https://gitlab.com/TheZoq2/tinypp

2024-11-15_21-38-36.mp4

@TheZoq2
Copy link

TheZoq2 commented Nov 16, 2024

Got sync from the document to the editor working by translating the scroll events into window/showDocument requests.

I also tried adding an additional request on hover to sync from editor to document, but that seems to silently fail and I can't find exactly what I need to send

From reading the source code, it seems like something along the lines of

{"jsonrpc":"2.0","method":"workspace/executeCommand","params":{"command":"tinymist.scrollPreview","arguments":["primary",{"character":0,"event":"panelScrollTo","filepath":""/home/frans/Documents/rust/tinymist-preview-proxy/test.typp","line":10}]},"id":"1_scroll"}

But it fails silently. @Myriad-Dreamin is there something I'm missing with that command?

@Myriad-Dreamin
Copy link
Owner

@TheZoq2 not sure the reason but your request is not a valid json.

@Myriad-Dreamin
Copy link
Owner

I updated a proposing solution to preview for simple editors:

tinymist/README.md

Lines 144 to 147 in a2cf51a

- Improve Typst Preview.
- Browsing mode: if no main file is specified, the preview will be in browsing mode and use the recently focused file as the main.
- Pin drop-down: Set the file to preview in the drop-down for clients that doesn't support passing arguments to the preview command.
- Render in web worker (another thread) to reduce overhead on the electron's main thread.

@TheZoq2
Copy link

TheZoq2 commented Nov 21, 2024

not sure the reason but your request is not a valid json.

Oh yeah, good point. Looks like that was me replacing the \" in my logs with " incorrectly

{"jsonrpc":"2.0","method":"workspace/executeCommand","params":{"command":"tinymist.scrollPreview","arguments":["primary",{"character":0,"event":"panelScrollTo","filepath":"/home/frans/Documents/rust/tinypp/test.typp","line":2}]},"id":"1_scroll"}

is what i'm sending

@Myriad-Dreamin Myriad-Dreamin added the editor-integration Features about editor integrations label Nov 25, 2024
@tmistele
Copy link
Contributor

Fwiw, here's another workaround. It basically adds tinymist.doStartPreview etc. as commands to a fork of helix. These commands can then be called from the <space>? menu or one can setup some key bindings.

tinymist-helix.mp4

@Myriad-Dreamin Myriad-Dreamin linked a pull request Jan 9, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor-integration Features about editor integrations enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants