Skip to content

Commit 526f1d8

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

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

lua/jupyter-api/init.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ 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+
if string.sub(data, -2) == "}\n" then
18+
read_pipe_buffer = read_pipe_buffer .. data
19+
else
20+
read_pipe_buffer = read_pipe_buffer .. string.sub(data, 1, -2)
1821
end
22+
if string.sub(read_pipe_buffer, -1) == "\n" then
23+
for split_data in read_pipe_buffer:gmatch("[^\r\n]+") do
24+
read_callback(err, vim.json.decode(split_data))
25+
end
26+
end
27+
read_pipe_buffer = ""
1928
else
2029
read_callback(err, data)
2130
end

0 commit comments

Comments
 (0)