Skip to content

Commit

Permalink
merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhuster committed Jan 19, 2025
1 parent 2808ed8 commit 8ef058b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
8 changes: 7 additions & 1 deletion lua/livepreview/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 6 additions & 8 deletions lua/livepreview/server/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<string, function(client:userdata):void>)
--- - on_events (table<string, function(client:userdata, data:{filename: string, events: FsEvent}):void>)
function Server:start(ip, port, opts)
self.server:bind(ip, port)
local on_events = opts.on_events
Expand All @@ -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,
})
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion plugin/livepreview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8ef058b

Please sign in to comment.