diff --git a/lua/codecompanion/health.lua b/lua/codecompanion/health.lua index 53a5b36f..cb85b6e8 100644 --- a/lua/codecompanion/health.lua +++ b/lua/codecompanion/health.lua @@ -1,7 +1,10 @@ -local health = vim.health or require("health") -local ok = health.ok or health.report_ok -local warn = health.warn or health.report_warn -local error = health.error or health.report_error +local config = require("codecompanion.config") + +local start = vim.health.start or vim.health.report_start +local ok = vim.health.ok or vim.health.report_ok +local info = vim.health.info or vim.health.report_info +local warn = vim.health.warn or vim.health.report_warn +local error = vim.health.error or vim.health.report_error local fmt = string.format @@ -9,17 +12,17 @@ local M = {} M.plugins = { { - name = "nvim-treesitter/nvim-treesitter", + name = "nvim-treesitter", }, { - name = "nvim-lua/plenary.nvim", + name = "plenary", }, { - name = "stevearc/dressing.nvim", + name = "dressing", optional = true, }, { - name = "folke/edgy.nvim", + name = "edgy", optional = true, }, } @@ -28,45 +31,74 @@ M.libraries = { "curl", } -local function library_available(cmd) - if vim.fn.executable(cmd) == 1 then +M.env_vars = { + { + name = config.options.api_key, + }, + { + name = config.options.org_api_key, + optional = true, + }, +} + +local function plugin_available(name) + local check, _ = pcall(require, name) + return check +end + +local function lib_available(lib) + if vim.fn.executable(lib) == 1 then return true end - return false end -local function plugin_available(name) - local check, _ = pcall(require, name) - return check +local function env_available(env) + if os.getenv(env) ~= nil then + return true + end + return false end function M.check() if vim.fn.has("nvim-0.9") == 0 then - health.error("CodeCompanion.nvim requires Neovim 0.9.0+") + error("codecompanion.nvim requires Neovim 0.9.0+") end - health.start("Checking neovim plugin dependencies") + start("codecompanion.nvim report") + + local log = require("codecompanion.utils.log") + info(fmt("Log file: %s", log.get_logfile())) for _, plugin in ipairs(M.plugins) do if plugin_available(plugin.name) then - ok(plugin.name .. " installed.") + ok(fmt("%s installed", plugin.name)) else if plugin.optional then - warn(fmt("Optional dependency '%s' not found.", plugin.name)) + warn(fmt("Optional %s dependency not found", plugin.name)) else - error(fmt("Dependency '%s' not found!", plugin.name)) + error(fmt("Dependency %s not found", plugin.name)) end end end - health.start("Checking library dependencies") - for _, library in ipairs(M.libraries) do - if library_available(library) then - ok(fmt("%s installed.", library)) + if lib_available(library) then + ok(fmt("%s installed", library)) else - error(fmt("%s not installed!", library)) + error(fmt("%s not installed", library)) + end + end + + for _, env in ipairs(M.env_vars) do + if env_available(env.name) then + ok(fmt("%s key found", env.name)) + else + if env.optional then + warn(fmt("Optional %s key not found", env.name)) + else + error(fmt("Key %s not found", env.name)) + end end end end diff --git a/lua/codecompanion/utils/log.lua b/lua/codecompanion/utils/log.lua index 7a22ebcc..9008dbce 100644 --- a/lua/codecompanion/utils/log.lua +++ b/lua/codecompanion/utils/log.lua @@ -235,6 +235,15 @@ local M = {} M.new = Logger.new +M.get_logfile = function() + local ok, stdpath = pcall(vim.fn.stdpath, "log") + if not ok then + stdpath = vim.fn.stdpath("cache") + end + + return files.join(stdpath, "codecompanion.log") +end + ---@param logger codecompanion.Logger M.set_root = function(logger) root = logger