@@ -6,19 +6,12 @@ local servers = require 'typst-preview.servers'
66
77local M = {}
88
9- --- Scroll all preview to cursor position.
10- function M .sync_with_cursor ()
11- for _ , ser in pairs (servers .get_all ()) do
12- servers .sync_with_cursor (ser )
13- end
14- end
15-
169--- Create user commands
1710function M .create_commands ()
1811 local function preview_off ()
1912 local path = utils .get_buf_path (0 )
2013
21- if path ~= ' ' and servers .remove ( config .opts .get_main_file (path )) then
14+ if path ~= ' ' and servers .remove { path = config .opts .get_main_file (path )} then
2215 utils .print ' Preview stopped'
2316 else
2417 utils .print ' Preview not running'
@@ -38,16 +31,20 @@ function M.create_commands()
3831 --- @param mode mode ?
3932 local function preview_on (mode )
4033 -- check if binaries are available and tell them to fetch first
41- for _ , bin in pairs (fetch .bins_to_fetch ()) do
42- if
43- not config .opts .dependencies_bin [bin .name ] and not fetch .up_to_date (bin )
44- then
45- utils .notify (
46- bin .name
47- .. ' not found or out of date\n Please run :TypstPreviewUpdate first!' ,
48- vim .log .levels .ERROR
49- )
50- return
34+ if config .opts .use_lsp then
35+ -- FIXME: Check for tinymist to be connected
36+ else
37+ for _ , bin in pairs (fetch .bins_to_fetch ()) do
38+ if
39+ not config .opts .dependencies_bin [bin .name ] and not fetch .up_to_date (bin )
40+ then
41+ utils .notify (
42+ bin .name
43+ .. ' not found or out of date\n Please run :TypstPreviewUpdate first!' ,
44+ vim .log .levels .ERROR
45+ )
46+ return
47+ end
5148 end
5249 end
5350
@@ -58,15 +55,13 @@ function M.create_commands()
5855
5956 mode = mode or ' document'
6057
61- local ser = servers .get (path )
62- if ser == nil or ser [mode ] == nil then
63- servers .init (path , mode , function (s )
64- events .listen (s )
65- end )
58+ local _ , ser = next (servers .get {path = path , mode = mode })
59+ if ser == nil then
60+ servers .init (path , mode , function (s ) end )
6661 else
67- local s = ser [ mode ]
62+ -- FIXME: try to ping the server to see whether it's really still alive
6863 print ' Opening another frontend'
69- utils .visit (s .link )
64+ utils .visit (ser .link )
7065 end
7166 end
7267
@@ -93,10 +88,7 @@ function M.create_commands()
9388 if path == nil then
9489 return
9590 end
96- local sers = servers .get (path )
97- if sers ~= nil then
98- mode = servers .get_last_mode (path )
99- end
91+ mode = servers .get_last_mode (path )
10092 end
10193
10294 preview_on (mode )
@@ -113,7 +105,7 @@ function M.create_commands()
113105 return
114106 end
115107
116- if servers .get ( path ) ~= nil then
108+ if next ( servers .get { path = path } ) ~= nil then
117109 preview_off ()
118110 else
119111 preview_on (servers .get_last_mode (path ))
@@ -130,7 +122,7 @@ function M.create_commands()
130122 config .set_follow_cursor (not config .get_follow_cursor ())
131123 end , {})
132124 vim .api .nvim_create_user_command (' TypstPreviewSyncCursor' , function ()
133- M . sync_with_cursor ()
125+ servers . scroll_preview ()
134126 end , {})
135127end
136128
0 commit comments