refactor(ai): streaming chunks to avoid excessive redraw. (#73)

* perf(ai): token streaming with quick refactoring

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>

* fix: window resize and AvanteSwitchProvider

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>

* revert: config change

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>

* chore: return early

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>

---------

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham
2024-08-18 15:03:25 -04:00
committed by GitHub
parent 0fddfc7d8f
commit 5fa4f701dd
6 changed files with 414 additions and 249 deletions

View File

@@ -1,8 +1,17 @@
local Range = require("avante.range")
local SelectionResult = require("avante.selection_result")
local M = {}
function M.trim_suffix(str, suffix)
return string.gsub(str, suffix .. "$", "")
---@param str string
---@param opts? {suffix?: string, prefix?: string}
function M.trim(str, opts)
if not opts then
return str
end
if opts.suffix then
return str:sub(-1) == opts.suffix and str:sub(1, -2) or str
elseif opts.prefix then
return str:sub(1, 1) == opts.prefix and str:sub(2) or str
end
end
function M.trim_line_number_prefix(line)
return line:gsub("^L%d+: ", "")