chore(utils): cleanup utils to support other than lazy.nvim (#256)

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham 2024-08-27 01:46:23 -04:00 committed by GitHub
parent 3369f732c5
commit 64cedd61d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 18 deletions

View File

@ -20,7 +20,11 @@ setmetatable(M, {
---@param plugin string
---@return boolean
M.has = function(plugin)
return require("lazy.core.config").plugins[plugin] ~= nil
local ok, LazyConfig = pcall(require, "lazy.core.config")
if ok then
return LazyConfig.plugins[plugin] ~= nil
end
return package.loaded[plugin] ~= nil
end
---@alias _ToggleSet fun(state: boolean): nil

View File

@ -1,21 +1,7 @@
local H = {}
local M = {}
H.get_os_name = function()
local os_name = vim.uv.os_uname().sysname
if os_name == "Linux" then
return "linux"
elseif os_name == "Darwin" then
return "macOS"
elseif os_name == "Windows_NT" then
return "windows"
else
error("Unsupported operating system: " .. os_name)
end
end
H.library_path = function()
local os_name = H.get_os_name()
local function get_library_path()
local os_name = require("avante.utils").get_os_name()
local ext = os_name == "linux" and "so" or (os_name == "macOS" and "dylib" or "dll")
local dirname = string.sub(debug.getinfo(1).source, 2, #"/tiktoken_lib.lua" * -1)
return dirname .. ("../build/?.%s"):format(ext)
@ -27,7 +13,7 @@ local trim_semicolon = function(s)
end
M.load = function()
local library_path = H.library_path()
local library_path = get_library_path()
if not string.find(package.cpath, library_path, 1, true) then
package.cpath = trim_semicolon(package.cpath) .. ";" .. library_path
end