From 4897bb458e87118672f8abb6c108653f37b58bdd Mon Sep 17 00:00:00 2001 From: Aaron Pham Date: Fri, 16 Aug 2024 03:19:07 -0400 Subject: [PATCH] fix(autocmd): make sure to load tiktoken on correct events (closes #16) (#24) Signed-off-by: Aaron Pham --- lua/avante/init.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lua/avante/init.lua b/lua/avante/init.lua index e21007226..b87ba9f2e 100644 --- a/lua/avante/init.lua +++ b/lua/avante/init.lua @@ -72,29 +72,37 @@ end function M.setup(opts) local ok, LazyConfig = pcall(require, "lazy.core.config") + + local load_path = function() + require("tiktoken_lib").load() + + tiktoken.setup("gpt-4o") + end + 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) + vim.schedule(load_path) else api.nvim_create_autocmd("User", { pattern = "LazyLoad", callback = function(event) if event.data == name then - require("tiktoken_lib").load() + load_path() return true end end, }) end + + api.nvim_create_autocmd("User", { + pattern = "VeryLazy", + callback = load_path, + }) end config.update(opts) - tiktoken.setup("gpt-4o") - diff.setup({ debug = false, -- log output to console default_mappings = config.get().mappings.diff, -- disable buffer local mapping created by this plugin