-
Notifications
You must be signed in to change notification settings - Fork 27
Add support for launching preview via lsp #88
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
base: master
Are you sure you want to change the base?
Conversation
Just noticed that this can be simplified further: |
Just pushed 2 additional commits: Now, the 3 commits in this PR are:
I'd argue that it might be the simplest way forward (if you think that these changes are generally appropriate for the plugin) to just go all the way and remove the old way of fetching binaries, and bump the version to EDIT: Note that as it is, this PR requires the latest tinymist (0.13.10) and probably also a recent neovim (not sure which version, however: I locally tested this on 0.11.0). |
ngl, can't wait for this to get pulled already haha |
Nice work. Is this usable as a fork for now? |
It should just work. I've been using it for the last few weeks (admittedly not much) without issues. There might of course be sharp edges and definitely missing documentation. EDIT: Would be happy about any feedback, in particular regarding any issues this branch might cause. |
I changed to your fork and branch and did not change my configuration, and the change resulted in:
The existing configuration Edit: Not saying this is the way to go, but at least it can work, with new configuration, this way. But morally you probably need to continue to respect the old configuration or document how to change configuration. diff --git lua/typst-preview/utils.lua lua/typst-preview/utils.lua
index 923641b..d19231f 100644
--- lua/typst-preview/utils.lua
+++ lua/typst-preview/utils.lua
@@ -6,7 +6,11 @@ local M = {}
function M.visit(link)
local opts = {}
if config.opts.open_cmd ~= nil then
- opts.cmd = {config.opts.open_cmd }
+ if type(config.opts.open_cmd) == "table" then
+ opts.cmd = config.opts.open_cmd
+ else
+ opts.cmd = {config.opts.open_cmd }
+ end
end
vim.ui.open('http://' .. link, opts)
end With that it "works", but :TypstPreview becomes more unreliable - w.r.t for example open preview twice in the same neovim, once each for two different buffers, I don't get that to work (it just opens the first preview again). Closing preview for a buffer and opening it with :TypstPreview again (opens to a browser window that doesn't connect to a live preview). So there are certainly challenges. 💥 QA bomb 😉 |
Went too far when refactoring this, unintentionally removing support for %s-formatting the open_cmd string. The main goal was to use vim.ui.open() to get the default handler if open_cmd is nil. That is still the case, if an explicit open_cmd is given, existing configs should work again.
Good call: I refactored the case where no
That's unexpected, opening previews for different buffers in a single nvim instance should definitely work (and it does for me). I don't really have an idea what could be going on here. (Unless that's actually due to the incorrect Could you enable debug logging for the plugin via {
'chomosuke/typst-preview.nvim',
opts = {
open_cmd = "firefox %s ...",
debug = true,
},
}, and provide the log from Rough edges that I'm aware of are
It doesn't really sound like those are your issue, however. The second point might contribute to why you perceive the plugin as less reliable than before?
😆 I was afraid it might be worse. Luckily, this actually simplifies the code in some ways. |
This is not new - unless the time until this happens has changed. typst-preview.nvim's preview generally behaves this way. |
So far so good! The new update works with unchanged config and it does support multiple previews at the same time, I guess for unknown reason why. (The |
@wisp3rwind @bluss To avoid resource leaking we made a timer to cleanup inactive preview instances. Perhaps we can improve it by some heartbeats from the webpage or the typst-preview.nvim, but introduce the risks to leak resource. Random guess: tinymist won't remove a preview instance if there is any connection to a webpage, but firefox/chrome will freeze a inactive webpage after a while to reduce energy consumption, which close the only active connection to the preview instance. |
I don't know if I can "report bugs" vs this branch here. I also don't know (right now) if this bug is specific to this branch. Anyway, here's the scenario:
It's unexpected that the preview shuts down just because an auxiliary buffer is closed. The main document is still open and the user still wants to continue editing the main document. Using pinMain or not has no effect on this. I have been using this branch since the last message (a few weeks), but I'm going back to the original preview. Two reasons:
If they can be fixed, then I don't know any other regressions. |
@bluss I recently wrote some integration tests for neovim, like pdf preview will work good when |
That's nice. I think the above stuff are something higher level, it's probably registered for some event and closing down a little too eagerly. I think, at least. Or, less likely?, there's something with the separate process that's more durable anyway. |
@bluss No, it is not testing some low-level internal things, but to wait and judge final PDF changes with some user actions for testing PDF preview. Some cheap event callbacks are made, which is more reliable than polling fs to wait PDF changes. Similarly, we can test typst-preview by sending user actions, or injecting or simulating rare input like system hibernation. |
Sure 👍 I'm not using Typst as much right now, but I still want this to be robust, so happy about any feedback. I can reproduce using your steps (5. not required as you note). Looks like a bug in the nvim plugin where we shutdown previews too eagerly when a language server detaches from a buffer. (I think what the code was intended to do is remove stale preview tasks when the server shuts down, but I got it quite wrong.) I'll look into fixing this later.
Need to check, but could be the same issue. |
Maybe a misunderstanding. I was just guessing that the bugs I reported here are some things that might be due to "it's probably registered for some event and closing down a little too eagerly." |
While I know this PR has benefits, I prefer the current model (without this PR) because the preview is more “durable” for example continuing unbroken during buffer reloads ( |
This add supports for starting preview via the language server instead of running a separate preview process and connecting to it via websocat. In particular, this means that an existing tinymist installation (e.g. system-wide or via mason) and its configuration via the regular language server configuration can be leveraged and there's no need to download executables. I'd hope that it also helps to save resources (RAM+CPU) due to running only a single process but I'm not sure whether that's actually true (i.e. whether the language server and preview task actually share resources).
Essentially, I had a look at the VSCode plugin, and replicated what it does. This turned out to be pleasantly simple given nvim's lsp infrastructure.
This is still a work-in-progress, I'd surprised if there were no regressions. I also left a bunch of
FIXME
comments that should probably be addressed. Documentation also needs updating.I tried to keep support for the previous installation method: Unless the
use_lsp = true
option is given, nothing user-visible should have changed. I did refactor quite a bit of the code, such asserver/init.lua
andserver/manager.lua
: the distincation was a bit vague anyway, and given how event handling changed, I was running into circular imports otherwisetask_id
as well. Given that there should be at most a handful of entries, performance is unlikely to be an issue.suppress
handling, which I disabled for now, see the FIXME. That can probably be handled at a lower level, though.)In its current state, this code works for me. Thus, I'd be happy about some initial feedback: