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

feat: support for tinymist preview #43

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ require 'typst-preview'.setup {
-- Warning: Be aware that your version might be older than the one
-- required.
dependencies_bin = {
['typst-preview'] = nil,
['websocat'] = nil
-- if you are using tinymist, just set ['typst-preview'] = "tinymist".
['typst-preview'] = nil,
['websocat'] = nil
},

-- This function will be called to determine the root of the typst project
Expand Down
1 change: 1 addition & 0 deletions doc/typst-preview.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ Set this to false to stop the preview from scrolling as the cursor moves.
*typst-preview.dependencies_bin*
Provide the path to binaries for dependencies.
Setting this will skip the download of the binary by the plugin.
Setting this to `'tinymist'` if you're using tinymist.
Warning: Be aware that your version might be older than the one
required.
Type: `table`, Default: `{['typst-preview'] = nil, ['websocat'] = nil}`
Expand Down
40 changes: 23 additions & 17 deletions lua/typst-preview/servers/factory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,32 @@ local function spawn(path, mode, callback)
local server_stderr = assert(vim.loop.new_pipe())
local typst_preview_bin = config.opts.dependencies_bin['typst-preview']
or (utils.get_data_path() .. fetch.get_typst_bin_name())
local args = {
'--partial-rendering',
'--invert-colors',
config.opts.invert_colors,
'--preview-mode',
mode,
'--no-open',
'--data-plane-host',
'127.0.0.1:0',
'--control-plane-host',
'127.0.0.1:0',
'--static-file-host',
'127.0.0.1:0',
'--root',
config.opts.get_root(path),
config.opts.get_main_file(path),
}
if typst_preview_bin:find 'tinymist' then
table.insert(args, 1, 'preview')
end
local server_handle, _ = assert(vim.loop.spawn(typst_preview_bin, {
args = {
'--partial-rendering',
'--invert-colors',
config.opts.invert_colors,
'--preview-mode',
mode,
'--no-open',
'--data-plane-host',
'127.0.0.1:0',
'--control-plane-host',
'127.0.0.1:0',
'--static-file-host',
'127.0.0.1:0',
'--root',
config.opts.get_root(path),
config.opts.get_main_file(path),
},
args = args,
stdio = { nil, server_stdout, server_stderr },
}))
utils.debug('spawning server ' .. typst_preview_bin .. ' with args:')
utils.debug(vim.inspect(args))

-- This will be gradually filled util it's ready to be fed to callback
-- Refactor if there's a third place callback would be called.
Expand Down