Fix some things

This commit is contained in:
2025-11-15 13:55:47 +00:00
parent 344623eaf6
commit 1c96d03649
3 changed files with 40 additions and 40 deletions

View File

@@ -51,7 +51,7 @@ helpers.open_term = function(opts)
end end
helpers.has_copilot = function() helpers.has_copilot = function()
return vim.fn.getenv('COPILOT_API_KEY') ~= nil return vim.fn.getenv('COPILOT_API_KEY') ~= vim.NIL
end end
return helpers return helpers

View File

@@ -21,8 +21,8 @@ return {
env = { env = {
url = vim.env.DEFAULT_OPENAI_API_BASE, url = vim.env.DEFAULT_OPENAI_API_BASE,
api_key = vim.env.DEFAULT_OPENAI_API_KEY, api_key = vim.env.DEFAULT_OPENAI_API_KEY,
chat_url = '/chat/completions', chat_url = '/v1/chat/completions',
models_endpoint = '/models', models_endpoint = '/v1/models',
}, },
schema = { schema = {
model = { model = {

View File

@@ -5,43 +5,43 @@ local i = ls.insert_node
local f = ls.function_node local f = ls.function_node
local function psr_namespace(_, snip) local function psr_namespace(_, snip)
local path = snip.env.TM_FILENAME_FULL or '' -- local path = snip.env.TM_FILENAME_FULL or ''
-- Get the directory of the path -- -- Get the directory of the path
local dir = vim.fs.dirname(path) -- local dir = vim.fs.dirname(path)
-- Loop through parent directories to find composer.json -- -- Loop through parent directories to find composer.json
while dir ~= '/' and dir ~= nil do -- while dir ~= '/' and dir ~= nil do
local composer_json_path = dir .. '/composer.json' -- local composer_json_path = dir .. '/composer.json'
if vim.fn.filereadable(composer_json_path) == 1 then -- if vim.fn.filereadable(composer_json_path) == 1 then
break -- break
end -- end
dir = vim.fs.dirname(dir) -- dir = vim.fs.dirname(dir)
end -- end
-- If no composer.json found, return empty string -- -- If no composer.json found, return empty string
if dir == '/' or dir == nil then -- if dir == '/' or dir == nil then
return '' -- return ''
end -- end
--
-- Decode composer.json and get PSR-4 autoload mappings -- -- Decode composer.json and get PSR-4 autoload mappings
local composer = vim.json.decode(vim.iter(vim.fn.readfile(dir .. '/composer.json')):join '') -- local composer = vim.json.decode(vim.iter(vim.fn.readfile(dir .. '/composer.json')):join '')
local psr4 = composer['autoload'] and composer['autoload']['psr-4'] -- local psr4 = composer['autoload'] and composer['autoload']['psr-4']
--
-- If no PSR-4 mappings, return empty string -- -- If no PSR-4 mappings, return empty string
if not psr4 then -- if not psr4 then
return '' -- return ''
end -- end
--
-- Get the relative path from the composer.json directory -- -- Get the relative path from the composer.json directory
local relative_path = path:sub(#dir + 2) -- local relative_path = path:sub(#dir + 2)
-- Loop through PSR-4 mappings -- -- Loop through PSR-4 mappings
for namespace, map in pairs(psr4) do -- for namespace, map in pairs(psr4) do
-- Check if the relative path matches the mapping -- -- Check if the relative path matches the mapping
if relative_path:match('^' .. map:gsub('/', '%%/')) then -- if relative_path:match('^' .. map:gsub('/', '%%/')) then
-- Extract the suffix of the path after the mapping, removing the filename -- -- Extract the suffix of the path after the mapping, removing the filename
local suffix = relative_path:sub(#map + 2):match('^(.*)/[^/]+%.php$') or '' -- local suffix = relative_path:sub(#map + 2):match('^(.*)/[^/]+%.php$') or ''
local trimmed = namespace:gsub('\\$', '') -- local trimmed = namespace:gsub('\\$', '')
return trimmed .. (suffix ~= '' and ('\\' .. suffix:gsub('/', '\\')) or '') -- return trimmed .. (suffix ~= '' and ('\\' .. suffix:gsub('/', '\\')) or '')
end -- end
end -- end
end end
local function class_name(args, snip) local function class_name(args, snip)