From 8ef058b6b73a98ac9a08cc3ec174d3ffc98bbbbc Mon Sep 17 00:00:00 2001 From: brianhuster Date: Sun, 19 Jan 2025 16:17:20 +0700 Subject: [PATCH] merge conflict --- lua/livepreview/init.lua | 8 +++++++- lua/livepreview/server/init.lua | 14 ++++++-------- plugin/livepreview.lua | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lua/livepreview/init.lua b/lua/livepreview/init.lua index 396803c..ef0c89a 100644 --- a/lua/livepreview/init.lua +++ b/lua/livepreview/init.lua @@ -70,7 +70,13 @@ function M.start(filepath, port) M.serverObj:start("127.0.0.1", port, { on_events = utils.supported_filetype(filepath) == "html" and { - LivePreviewDirChanged = function(client) + ---@param client userdata + ---@param data {filename: string, event: FsEvent} + LivePreviewDirChanged = function(client, data) + if not vim.regex([[\.\(html\|css\|js\)$]]):match_str(data.filename) then + return + end + server.websocket.send_json(client, { type = "reload" }) end, } or { diff --git a/lua/livepreview/server/init.lua b/lua/livepreview/server/init.lua index 05fd8ac..d9dfecd 100644 --- a/lua/livepreview/server/init.lua +++ b/lua/livepreview/server/init.lua @@ -12,6 +12,10 @@ local supported_filetype = require("livepreview.utils").supported_filetype local fswatch = require("livepreview.server.fswatch") local api = vim.api +---@class FsEvent +---@field change boolean +---@field rename boolean + ---@class Server ---To call this class, do ---```lua @@ -147,7 +151,7 @@ end --- @param ip string: IP address to bind to --- @param port number: port to bind to --- @param opts ServerStartOptions: a table with the following fields ---- - on_events (table) +--- - on_events (table) function Server:start(ip, port, opts) self.server:bind(ip, port) local on_events = opts.on_events @@ -161,11 +165,8 @@ function Server:start(ip, port, opts) group = "LivePreview", pattern = k, callback = function(param) - if not param.data.filename:match("%.(html|css|js)$") then - return - end for _, client in ipairs(M.connecting_clients) do - v(client) + v(client, param.data) end end, }) @@ -184,9 +185,6 @@ function Server:start(ip, port, opts) end self.server:listen(128, function(err) - if err then - end - --- Connect to client local client = uv.new_tcp() self.server:accept(client) diff --git a/plugin/livepreview.lua b/plugin/livepreview.lua index 1aeebd7..a0f1c37 100644 --- a/plugin/livepreview.lua +++ b/plugin/livepreview.lua @@ -38,7 +38,7 @@ api.nvim_create_user_command(cmd, function(cmd_opts) if cmd_opts.fargs[2] ~= nil then filepath = cmd_opts.fargs[2] if not utils.is_absolute_path(filepath) then - filepath = utils.joinpath(vim.uv.cwd(), filepath) + filepath = fs.joinpath(vim.uv.cwd(), filepath) end else filepath = api.nvim_buf_get_name(0)