chomosuke / typst-preview.nvim

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

Question: Do I need an auto-save plugin for live preview? #32

Open jacob-jacob-jacob opened 1 month ago

jacob-jacob-jacob commented 1 month ago

The browser for me only updates when I write the file (:w). I'm relatively new to VIM, so not sure if this is a problem on my side - the vim configuration is relatively vanilla though.

I do not understand if this should be working, or if a plugin like https://github.com/pocco81/auto-save.nvim is assumed to be installed? If so, would you mind sharing your auto-safe configuration?

Thank you for the great plugin!

chomosuke commented 1 month ago

Nope, that's not supposed to happen. I'd appreciate it if you can share your config so that I can investigate further into this issue.

jacob-jacob-jacob commented 1 month ago

Hello, thank you very much! This is my config

My init.lua:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

-- Example using a list of specs with the default options
vim.g.mapleader = " " -- Make sure to set `mapleader` before lazy so your mappings are correct
vim.g.maplocalleader = "\\" -- Same for `maplocalleader`

local typst_preview = {
  'chomosuke/typst-preview.nvim',
  lazy = false, -- or ft = 'typst'
  version = '0.3.*',
  build = function() require 'typst-preview'.update() end,
}

require("lazy").setup({
    typst_preview
})

Basically, I am only installing the lazy package manager and using an autosave feature (however, it did not work before the autosaving either).

Also, to add, I am on Manjaro linux and NVIM v0.9.5.

I am not supposed to be installing https://github.com/Enter-tainer/typst-preview manually, right? The above should pull in that plugin and work without any other config?

chomosuke commented 1 month ago

Yup, your config are supposed to work. In fact, I copied your config and it did work for me. May I ask what OS are you running? It could also help if you set debug = true and post the output of :mes.

jacob-jacob-jacob commented 1 month ago

Hello. Thanks for the fast answer! I am running Manjaro Linux.

My new config, with debug = true:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

-- Example using a list of specs with the default options
vim.g.mapleader = " " -- Make sure to set `mapleader` before lazy so your mappings are correct
vim.g.maplocalleader = "\\" -- Same for `maplocalleader`

local typst_preview = {
  debug = true,
  'chomosuke/typst-preview.nvim',
  lazy = false, -- or ft = 'typst'
  version = '0.3.*',
  build = function() require 'typst-preview'.update() end,
}

require("lazy").setup({
    typst_preview
})

When I open the file with nvim, and then do :TypstPreview, the preview opens correctly. When I then type in some stuff in insert mode (withot saving), :mes does not show me anything.

When I write the file, the preview is updated, and afterwards, :mes shows me

"filename.typ" 183L, 9715B written

but nothing else.

jacob-jacob-jacob commented 1 month ago

I just reinstalled nvim (and deleted everything in .config/nvim as well as .local/share/nvim), and only copied over the above config. But I am still getting the same behaviour as before.

chomosuke commented 1 month ago

Sorry for the late reply. I forgot to tell you how to set debug = true, you need to do this

local typst_preview = {
  'chomosuke/typst-preview.nvim',
  lazy = false, -- or ft = 'typst'
  version = '0.3.*',
  config = function()
    require('typst-preview').setup { debug = true }
  end,
  build = function() require 'typst-preview'.update() end,
}
PancakeFriday commented 1 month ago

Hello, I have the same issue. The following is the output of :mes after setting debug:

[2024-06-03T08:48:05Z INFO  typst_preview] Arguments: CliArguments {
        preview: PreviewArgs {
            data_plane_host: "127.0.0.1:0",
            control_plane_host: "127.0.0.1:0",
            enable_partial_rendering: true,
            invert_colors: "never",
        },
        preview_mode: Document,
        static_file_host: "127.0.0.1:0",
        dont_open_in_browser: true,
        font_paths: [],
        root: Some(
            "/home/user/Workspace/typst/test",
        ),
        input: "/home/user/Workspace/typst/test/main.typ",
    }
[2024-06-03T08:48:06Z INFO  typst_preview] Previewer: typst actor spawned
[2024-06-03T08:48:06Z DEBUG typst_preview::actor::typst] TypstActor: waiting for message
Connecting to server
websocat connecting to: ws://127.0.0.1:46281/
[2024-06-03T08:48:06Z INFO  typst_preview] Control plane server listening on: 127.0.0.1:46281
[2024-06-03T08:48:06Z DEBUG typst_ts_compiler::service::watch] start watching files...
[2024-06-03T08:48:06Z INFO  typst_preview] Data plane server listening on: 127.0.0.1:37357
[2024-06-03T08:48:06Z DEBUG typst_ts_compiler::service::compile] CompileActor: initialized
[2024-06-03T08:48:06Z DEBUG typst_ts_compiler::service::compile] CompileActor: fs event incoming None
[2024-06-03T08:48:06Z INFO  typst_ts_compiler::service::diag::console] /main.typ: compiling ...

Setting link
[2024-06-03T08:48:06Z INFO  typst_preview] Static file server listening on: 127.0.0.1:37257
Opening preview with command: xdg-open http://127.0.0.1:37257
[2024-06-03T08:48:06Z INFO  typst_preview] Peer address: 127.0.0.1:50252
[2024-06-03T08:48:06Z INFO  typst_preview] New WebSocket connection: 127.0.0.1:50252
websocat said: {"event":"syncEditorChanges"}
{"event":"compileStatus","kind":"Compiling"}
[2024-06-03T08:48:06Z INFO  typst_ts_compiler::service::diag::console] /main.typ: Compilation succeeded in 139.
s

websocat said: {"event":"compileStatus","kind":"CompileSuccess"}
[2024-06-03T08:48:06Z DEBUG typst_ts_compiler::service::compile] CompileActor: fs event incoming Some(Update(Fi
eSet { removes: [], inserts: [("/home/user/Workspace/typst/test/main.typ", FileSnapshot { mtim
emTime { tv_sec: 1717404458, tv_nsec: 73648087 }, content: FileContent { len: 68358 } })] }))
[2024-06-03T08:48:06Z INFO  typst_ts_compiler::service::diag::console] /main.typ: compiling ...
[2024-06-03T08:48:06Z INFO  typst_ts_compiler::service::diag::console] /main.typ: Compilation succeeded in 93.3
78µs

websocat said: {"event":"compileStatus","kind":"Compiling"}
{"event":"compileStatus","kind":"CompileSuccess"}
[2024-06-03T08:48:07Z INFO  typst_preview] Serve frontend: Document
[2024-06-03T08:48:07Z INFO  typst_preview] Peer address: 127.0.0.1:38990
[2024-06-03T08:48:07Z INFO  typst_preview] New WebSocket connection: 127.0.0.1:38990
[2024-06-03T08:48:07Z DEBUG typst_preview::actor::render] OutlineRenderActor: waiting for message
[2024-06-03T08:48:07Z DEBUG typst_preview::actor::render] RenderActor: waiting for message
[2024-06-03T08:48:07Z DEBUG typst_preview::actor::render] OutlineRenderActor: received message: RenderFullLates
t
[2024-06-03T08:48:07Z DEBUG typst_preview::actor::render] RenderActor: has_full_render: true
[2024-06-03T08:48:07Z DEBUG typst_preview::actor::render] OutlineRenderActor: sending outline
[2024-06-03T08:48:07Z DEBUG typst_preview::actor::render] OutlineRenderActor: waiting for message
websocat said: {"event":"outline","items":[]}
[2024-06-03T08:48:07Z DEBUG typst_preview::actor::render] RenderActor: waiting for message
scroll to line: 0, character: 0
[2024-06-03T08:48:13Z DEBUG typst_preview::actor::editor] EditorActor: received message from editor: SrcToDocJu
mpRequest { filepath: "/home/user/Workspace/typst/test/main.typ", line: 0, character: 0 }
[2024-06-03T08:48:13Z DEBUG typst_preview::actor::typst] TypstActor: processing src2doc: SrcToDocJumpRequest {
filepath: "/home/user/Workspace/typst/test/main.typ", line: 0, character: 0 }
[2024-06-03T08:48:13Z DEBUG typst_ts_compiler::service::compile] CompileActor: execute task

I am using LunarVim release-1.3/neovim-0.9-d1c1bace with neovim 0.9.1