perf: make load ultra ultra fast (#14)

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham 2024-08-15 21:08:26 -04:00 committed by GitHub
parent 333bf73bcb
commit e3c162aad3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,7 +3,26 @@ local sidebar = require("avante.sidebar")
local config = require("avante.config")
function M.setup(opts)
require("tiktoken_lib").load()
local ok, LazyConfig = pcall(require, "lazy.core.config")
if ok then
local name = "avante.nvim"
if LazyConfig.plugins[name] and LazyConfig.plugins[name]._.loaded then
vim.schedule(function()
require("tiktoken_lib").load()
end)
else
vim.api.nvim_create_autocmd("User", {
pattern = "LazyLoad",
callback = function(event)
if event.data == name then
require("tiktoken_lib").load()
return true
end
end,
})
end
end
config.update(opts)
sidebar.setup()
end