Skip to content

Commit

Permalink
health: Check to see if user has called setup or not
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed Jan 5, 2024
1 parent 817f1f3 commit fe5b4b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lua/sg/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ local M = {}
local blocking = require("sg.utils").blocking

local report_nvim = function()
if vim.version.cmp(vim.version(), { 0, 9, 0 }) >= 0 then
vim.health.ok(string.format("Valid nvim version: %s", vim.version()))
if vim.version.cmp(vim.version(), { 0, 9, 4 }) >= 0 then
vim.health.ok(string.format("Valid nvim version: %s", tostring(vim.version())))
return true
else
vim.health.error "Invalid nvim version. Upgrade to at least 0.9.0"
vim.health.error "Invalid nvim version. Upgrade to at least 0.9.4"
return false
end
end
Expand Down Expand Up @@ -173,7 +173,17 @@ M.check = function()
local uname = vim.loop.os_uname()
vim.health.info(string.format("Machine: %s, sysname: %s", uname.machine, uname.sysname))

ok = report_nvim() and ok
if not report_nvim() then
vim.health.error "Invalid nvim version. Upgrade to at least 0.9.4 or nightly"
return
end

if not require("sg")._setup_has_been_called then
vim.health.error "sg.nvim has not been setup. See ':help sg' for more info."
vim.health.error "Run `require('sg').setup()` somewhere in your configuration"
return
end

ok = report_lib() and ok
ok = report_nvim_agent() and ok
ok = report_agent() and ok
Expand Down
6 changes: 6 additions & 0 deletions lua/sg/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

local M = {}

-- Private var to determine if setup has been called.
-- Primarily usesful for health checks and reporting information to users
M._setup_has_been_called = false

--- Setup sourcegraph
---@param opts sg.config
M.setup = function(opts)
Expand All @@ -34,6 +38,8 @@ M.setup = function(opts)
require("sg.request").start()
require("sg.cody.plugin.agent").setup(config)
require("sg.cody.plugin.commands").setup(config)

M._setup_has_been_called = true
end

return M

0 comments on commit fe5b4b2

Please sign in to comment.