Skip to content

Commit 2f862eb

Browse files
committed
fix: handle use a buffer to handle long messages
1 parent 1526bfb commit 2f862eb

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

lua/jupyter-api/init.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ M.connect = function(connection_info, callback)
1010
local read_pipe = vim.uv.new_pipe()
1111
assert(read_pipe ~= nil)
1212
read_pipe:open(conn.read_pipe_fd)
13+
local read_pipe_buffer = ""
1314
read_pipe:read_start(function(err, data)
1415
assert(read_callback, "Was sent a message with no read callback!\nThe message: " .. data)
1516
if data then
16-
for split_data in data:gmatch("[^\r\n]+") do
17-
read_callback(err, vim.json.decode(split_data))
17+
read_pipe_buffer = read_pipe_buffer .. data
18+
vim.schedule(function ()
19+
vim.notify(read_pipe_buffer)
20+
end)
21+
if string.sub(read_pipe_buffer, -1) == "\n" then
22+
for split_data in read_pipe_buffer:gmatch("[^\r\n]+") do
23+
read_callback(err, vim.json.decode(split_data))
24+
end
1825
end
26+
read_pipe_buffer = ""
1927
else
2028
read_callback(err, data)
2129
end

0 commit comments

Comments
 (0)