chore(utils): cleanup utils to support other than lazy.nvim (#256)
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
parent
3369f732c5
commit
64cedd61d5
@ -20,7 +20,11 @@ setmetatable(M, {
|
|||||||
---@param plugin string
|
---@param plugin string
|
||||||
---@return boolean
|
---@return boolean
|
||||||
M.has = function(plugin)
|
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
|
end
|
||||||
|
|
||||||
---@alias _ToggleSet fun(state: boolean): nil
|
---@alias _ToggleSet fun(state: boolean): nil
|
||||||
|
@ -1,21 +1,7 @@
|
|||||||
local H = {}
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
H.get_os_name = function()
|
local function get_library_path()
|
||||||
local os_name = vim.uv.os_uname().sysname
|
local os_name = require("avante.utils").get_os_name()
|
||||||
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 ext = os_name == "linux" and "so" or (os_name == "macOS" and "dylib" or "dll")
|
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)
|
local dirname = string.sub(debug.getinfo(1).source, 2, #"/tiktoken_lib.lua" * -1)
|
||||||
return dirname .. ("../build/?.%s"):format(ext)
|
return dirname .. ("../build/?.%s"):format(ext)
|
||||||
@ -27,7 +13,7 @@ local trim_semicolon = function(s)
|
|||||||
end
|
end
|
||||||
|
|
||||||
M.load = function()
|
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
|
if not string.find(package.cpath, library_path, 1, true) then
|
||||||
package.cpath = trim_semicolon(package.cpath) .. ";" .. library_path
|
package.cpath = trim_semicolon(package.cpath) .. ";" .. library_path
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user