From 445b9df179dd7d5c327dcfcb0a726112f1d96737 Mon Sep 17 00:00:00 2001 From: Antoine Gaudreau Simard Date: Sun, 6 Apr 2025 09:44:17 -0400 Subject: [PATCH] test fix --- lua/copilot/client/config.lua | 12 ++++++++++++ lua/copilot/client/init.lua | 37 +++++------------------------------ 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/lua/copilot/client/config.lua b/lua/copilot/client/config.lua index 7f8ec6b2..42248a65 100644 --- a/lua/copilot/client/config.lua +++ b/lua/copilot/client/config.lua @@ -6,6 +6,9 @@ local lsp = require("copilot.lsp") local utils = require("copilot.client.utils") local M = {} +---@type table +local callbacks = {} + ---@param overrides table ---@param client CopilotClient function M.prepare_client_config(overrides, client) @@ -109,6 +112,10 @@ function M.prepare_client_config(overrides, client) -- prevent requests to copilot prior to being initialized client.initialized = true + + for _, callback in ipairs(callbacks) do + callback(lsp_client) + end end) end, on_exit = function(code, _, client_id) @@ -135,4 +142,9 @@ function M.prepare_client_config(overrides, client) }, overrides) end +---@param callback fun(client:table) +function M.add_callback(callback) + table.insert(callbacks, callback) +end + return M diff --git a/lua/copilot/client/init.lua b/lua/copilot/client/init.lua index 35753120..8e06f149 100644 --- a/lua/copilot/client/init.lua +++ b/lua/copilot/client/init.lua @@ -3,6 +3,7 @@ local util = require("copilot.util") local logger = require("copilot.logger") local lsp = require("copilot.lsp") local utils = require("copilot.client.utils") +local client_config = require("copilot.client.config") local is_disabled = false @@ -107,6 +108,7 @@ function M.use_client(callback) return end + client_config.add_callback(callback) local client_id, err = vim.lsp.start(M.config) if not client_id then @@ -115,40 +117,11 @@ function M.use_client(callback) end store_client_id(client_id) - - client = M.get() --[[@as table]] - end - - if client.initialized then + elseif not client.initialized then + client_config.add_callback(callback) + else callback(client) - return end - - logger.error("client is not initialized yet") - -- Following code is commented out for now because: - -- 1) I am hoping it is not needed anymore and - -- 2) It causes issues with testing >_< - -- - -- local timer, err, _ = vim.uv.new_timer() - -- - -- if not timer then - -- logger.error(string.format("error creating timer: %s", err)) - -- return - -- end - -- - -- timer:start( - -- 0, - -- 100, - -- vim.schedule_wrap(function() - -- if client.initialized and not timer:is_closing() then - -- timer:stop() - -- timer:close() - -- callback(client) - -- else - -- logger.error("client not initialized yet") - -- end - -- end) - -- ) end function M.setup()