optimize: streaming diff performance (#2150)
This commit is contained in:
@@ -113,11 +113,22 @@ function M.func(opts, on_log, on_complete, session_ctx)
|
|||||||
|
|
||||||
local is_streaming = opts.streaming or false
|
local is_streaming = opts.streaming or false
|
||||||
|
|
||||||
|
if is_streaming then
|
||||||
|
local streaming_diff_lines_count = Utils.count_lines(opts.diff)
|
||||||
|
session_ctx.streaming_diff_lines_count_history = session_ctx.streaming_diff_lines_count_history or {}
|
||||||
|
local prev_streaming_diff_lines_count = session_ctx.streaming_diff_lines_count_history[opts.tool_use_id]
|
||||||
|
if streaming_diff_lines_count == prev_streaming_diff_lines_count then
|
||||||
|
return false, "Diff lines count hasn't changed"
|
||||||
|
end
|
||||||
|
session_ctx.streaming_diff_lines_count_history[opts.tool_use_id] = streaming_diff_lines_count
|
||||||
|
end
|
||||||
|
|
||||||
local diff = fix_diff(opts.diff)
|
local diff = fix_diff(opts.diff)
|
||||||
|
|
||||||
if on_log and diff ~= opts.diff then on_log("diff fixed") end
|
if on_log and diff ~= opts.diff then on_log("diff fixed") end
|
||||||
|
|
||||||
local diff_lines = vim.split(diff, "\n")
|
local diff_lines = vim.split(diff, "\n")
|
||||||
|
|
||||||
local is_searching = false
|
local is_searching = false
|
||||||
local is_replacing = false
|
local is_replacing = false
|
||||||
local current_old_lines = {}
|
local current_old_lines = {}
|
||||||
|
|||||||
@@ -1646,4 +1646,20 @@ function M.message_to_text(message, messages)
|
|||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.count_lines(str)
|
||||||
|
if not str or str == "" then return 0 end
|
||||||
|
|
||||||
|
local count = 1
|
||||||
|
local len = #str
|
||||||
|
local newline_byte = string.byte("\n")
|
||||||
|
|
||||||
|
for i = 1, len do
|
||||||
|
if str:byte(i) == newline_byte then count = count + 1 end
|
||||||
|
end
|
||||||
|
|
||||||
|
if str:byte(len) == newline_byte then count = count - 1 end
|
||||||
|
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user