Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lua/gitlab/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,19 @@ M.check = function(return_results)
},
}

local go_version_problem = version.check_go_version()
if go_version_problem ~= nil then
table.insert(warnings, go_version_problem)
if state.settings.server.binary_provided then
local binary_exists = vim.loop.fs_stat(state.settings.server.binary)
if binary_exists == nil then
table.insert(
errors,
string.format("The user-provided server path (%s) does not exist", state.settings.server.binary)
)
end
else
local go_version_problem = version.check_go_version()
if go_version_problem ~= nil then
table.insert(errors, go_version_problem)
end
end

for _, dep in ipairs(required_deps) do
Expand Down
7 changes: 0 additions & 7 deletions lua/gitlab/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ local summary = require("gitlab.actions.summary")
local data = require("gitlab.actions.data")
local assignees_and_reviewers = require("gitlab.actions.assignees_and_reviewers")
local comment = require("gitlab.actions.comment")
local version = require("gitlab.version")
local pipeline = require("gitlab.actions.pipeline")
local create_mr = require("gitlab.actions.create_mr")
local approvals = require("gitlab.actions.approvals")
Expand All @@ -37,12 +36,6 @@ local function setup(args)
args = {}
end

local version_issue = version.check_go_version()
if version_issue ~= nil then
u.notify(version_issue, vim.log.levels.ERROR)
return
end

state.merge_settings(args) -- Merges user settings with default settings
server.build() -- Builds the Go binary if it doesn't exist
state.set_global_keymaps() -- Sets keymaps that are not bound to a specific buffer
Expand Down
22 changes: 10 additions & 12 deletions lua/gitlab/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
local state = require("gitlab.state")
local u = require("gitlab.utils")
local job = require("gitlab.job")
local version = require("gitlab.version")
local M = {}

-- Builds the binary if it doesn't exist, and starts the server. If the pre-existing binary has an older
Expand All @@ -23,8 +24,8 @@ M.build_and_start = function(callback)
callback()
return
end
M.get_version(function(version)
if version.plugin_version ~= version.binary_version then
M.get_version(function(versions)
if versions.plugin_version ~= versions.binary_version then
M.shutdown(function()
if M.build(true) then
M.start(callback)
Expand Down Expand Up @@ -105,14 +106,11 @@ M.build = function(override)

-- If the user provided a path to the server, don't build it.
if state.settings.server.binary_provided then
local binary_exists = vim.loop.fs_stat(state.settings.server.binary)
if binary_exists == nil then
u.notify(
string.format("The user-provided server path (%s) does not exist.", state.settings.server.binary),
vim.log.levels.ERROR
)
return false
end
return
end

local version_issue = version.check_go_version()
if version_issue ~= nil then
return
end

Expand Down Expand Up @@ -150,9 +148,9 @@ M.build = function(override)
local version_output = vim
.system({ "git", "describe", "--tags", "--always" }, { cwd = state.settings.root_path })
:wait()
local version = version_output.code == 0 and vim.trim(version_output.stdout) or "unknown"
local plugin_version = version_output.code == 0 and vim.trim(version_output.stdout) or "unknown"

local ldflags = string.format("-X main.Version=%s", version)
local ldflags = string.format("-X main.Version=%s", plugin_version)
local res = vim
.system(
{ "go", "build", "-buildvcs=false", "-ldflags", ldflags, "-o", state.settings.server.binary },
Expand Down
21 changes: 11 additions & 10 deletions lua/gitlab/version.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
local M = {}

local minimum_go_version = "1.25.1"

M.is_go_valid = function()
local go_version = io.popen("go version"):read("*a")
if go_version then
local major, minor, _ = go_version:match("(%d+)%.(%d+)%.?(%d*)")
if major and tonumber(major) >= 1 and tonumber(minor) >= 25 then
return true
else
return false
end
else
local has_go, go = pcall(vim.system, { "go", "version" })
if not has_go then
return false
end

local go_version = vim.version.parse(go:wait().stdout, { strict = false })
return go_version ~= nil and vim.version.ge(go_version, minimum_go_version)
end

M.check_go_version = function()
local has_version = M.is_go_valid()
if not has_version then
return "Go is not installed, or version is older than 1.25.1. Please reinstall up-to-date Go version: https://go.dev/dl/"
return string.format(
"Go is not installed, or version is older than %s. Please reinstall up-to-date Go version: https://go.dev/dl/",
minimum_go_version
)
end
end

Expand Down
Loading