Skip to content

Commit

Permalink
fix(autocmd): make sure to load tiktoken on correct events (manually … (
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone authored Aug 16, 2024
1 parent ce5d421 commit 4b5c52c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
20 changes: 16 additions & 4 deletions lua/avante/init.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
local M = {}
local tiktoken = require("avante.tiktoken")
local sidebar = require("avante.sidebar")
local config = require("avante.config")

local api = vim.api

function M.setup(opts)
local load_path = function()
require("tiktoken_lib").load()

tiktoken.setup("gpt-4o")
end

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)
vim.schedule(load_path)
else
vim.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)
Expand Down
3 changes: 0 additions & 3 deletions lua/avante/sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ local M = {}
local Path = require("plenary.path")
local n = require("nui-components")
local diff = require("avante.diff")
local tiktoken = require("avante.tiktoken")
local config = require("avante.config")
local ai_bot = require("avante.ai_bot")
local api = vim.api
Expand Down Expand Up @@ -630,8 +629,6 @@ function M.setup()
_cur_code_buf = bufnr
end

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 4b5c52c

Please sign in to comment.