Skip to content

Commit d84ad37

Browse files
committed
fix #362
1 parent 4bbcbe7 commit d84ad37

2 files changed

Lines changed: 18 additions & 24 deletions

File tree

lua/livepreview/init.lua

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ function M.start(filepath, port)
5353
M.close()
5454

5555
M.serverObj = server.Server:new(config.config.dynamic_root and vim.fs.dirname(filepath) or nil)
56-
vim.wait(50, function()
5756
local function onTextChanged(client)
5857
local bufname = vim.api.nvim_buf_get_name(0)
5958
if not utils.supported_filetype(bufname) or utils.supported_filetype(bufname) == "html" then
@@ -67,27 +66,24 @@ function M.start(filepath, port)
6766
server.websocket.send_json(client, message)
6867
end
6968

70-
M.serverObj:start(config.config.address, port, {
71-
on_events = utils.supported_filetype(filepath) == "html"
72-
and {
73-
---@param client uv_tcp_t
74-
---@param data {filename: string, event: FsEvent}
75-
LivePreviewDirChanged = function(client, data)
76-
if not vim.regex([[\.\(html\|css\|js\)$]]):match_str(data.filename) then
77-
return
78-
end
79-
80-
server.websocket.send_json(client, { type = "reload" })
81-
end,
82-
}
83-
or {
84-
TextChanged = vim.schedule_wrap(onTextChanged),
85-
TextChangedI = vim.schedule_wrap(onTextChanged),
86-
},
87-
})
88-
89-
return true
90-
end, 98)
69+
M.serverObj:start(config.config.address, port, {
70+
on_events = utils.supported_filetype(filepath) == "html"
71+
and {
72+
---@param client uv_tcp_t
73+
---@param data {filename: string, event: FsEvent}
74+
LivePreviewDirChanged = function(client, data)
75+
if not vim.regex([[\.\(html\|css\|js\)$]]):match_str(data.filename) then
76+
return
77+
end
78+
79+
server.websocket.send_json(client, { type = "reload" })
80+
end,
81+
}
82+
or {
83+
TextChanged = vim.schedule_wrap(onTextChanged),
84+
TextChangedI = vim.schedule_wrap(onTextChanged),
85+
},
86+
})
9187

9288
return true
9389
end

lua/livepreview/server/init.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ function Server:start(ip, port, opts)
211211
end)
212212
table.insert(M.connecting_clients, client)
213213
end)
214-
215-
uv.run()
216214
end
217215

218216
--- Stop the server

0 commit comments

Comments
 (0)