Skip to content

Commit

Permalink
fix(autocmd): make sure to load tiktoken on correct events (closes #16)…
Browse files Browse the repository at this point in the history
… (#24)

Signed-off-by: Aaron Pham <[email protected]>
  • Loading branch information
aarnphm authored Aug 16, 2024
1 parent a937c6a commit 4897bb4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lua/avante/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4897bb4

Please sign in to comment.