perf: async cache initialization and remove deepcopy
Problem: first completion request blocked the UI with a synchronous vim.system():wait() call, and every subsequent key completion unnecessarily deep-copied the entire cache. Solution: use vim.system with an async callback to initialize the cache without blocking. Queue pending completion requests during loading and serve them once parsing finishes. Return cached keys directly instead of deep-copying.
This commit is contained in:
parent
dfbae31684
commit
8bb6a81d1f
2 changed files with 55 additions and 25 deletions
|
|
@ -19,24 +19,31 @@ local BASH_COMPLETION = table.concat({
|
|||
}, '\n')
|
||||
|
||||
local function mock_system()
|
||||
local original = vim.system
|
||||
local original_system = vim.system
|
||||
local original_schedule = vim.schedule
|
||||
---@diagnostic disable-next-line: duplicate-set-field
|
||||
vim.system = function(cmd)
|
||||
vim.system = function(cmd, _, on_exit)
|
||||
if cmd[1] == 'ghostty' then
|
||||
return {
|
||||
wait = function()
|
||||
return { stdout = CONFIG_DOCS, code = 0 }
|
||||
end,
|
||||
}
|
||||
local result = { stdout = CONFIG_DOCS, code = 0 }
|
||||
if on_exit then
|
||||
on_exit(result)
|
||||
return {}
|
||||
end
|
||||
return { wait = function() return result end }
|
||||
end
|
||||
return {
|
||||
wait = function()
|
||||
return { stdout = '', code = 1 }
|
||||
end,
|
||||
}
|
||||
local result = { stdout = '', code = 1 }
|
||||
if on_exit then
|
||||
on_exit(result)
|
||||
return {}
|
||||
end
|
||||
return { wait = function() return result end }
|
||||
end
|
||||
vim.schedule = function(fn)
|
||||
fn()
|
||||
end
|
||||
return function()
|
||||
vim.system = original
|
||||
vim.system = original_system
|
||||
vim.schedule = original_schedule
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue