Skip to content

Commit

Permalink
refactor(health): show the program version if not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
lopi-py committed Aug 20, 2024
1 parent efff92f commit 5e84736
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions lua/luau-lsp/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,28 @@ local config = require "luau-lsp.config"

local M = {}

---@param opts { name: string, cmd: string[], version?: string, required: boolean? }
---@param opts { name: string, cmd: string[], version?: string, optional: boolean? }
local function check_executable(opts)
local ok, job = pcall(Job.new, Job, {
command = vim.fn.exepath(opts.cmd[1]),
args = vim.list_slice(opts.cmd, 2),
})

if not ok then
local report = opts.required == false and vim.health.warn or vim.health.error
local report = opts.optional and vim.health.warn or vim.health.error
report(string.format("%s: not available", opts.name))
return
end

if opts.version then
local version = table.concat(job:sync(), "\n")
if vim.version.ge(version, opts.version) then
vim.health.ok(string.format("%s: `%s`", opts.name, tostring(version)))
else
vim.health.error(
string.format(
"%s: required version is `%s`, found `%s`",
opts.name,
opts.version:gsub("a", "b"),
version
)
)
end
local version = table.concat(job:sync(), "\n")
if opts.version and vim.version.lt(version, opts.version) then
vim.health.error(
string.format("%s: required version is `%s`, found `%s`", opts.name, opts.version, version)
)
return
end

vim.health.ok(string.format("%s: `%s`", opts.name, version))
end

function M.check()
Expand Down Expand Up @@ -59,9 +53,11 @@ function M.check()
name = "rojo",
cmd = { config.get().sourcemap.rojo_path, "--version" },
version = "7.3.0",
required = config.get().platform.type == "roblox"
and config.get().sourcemap.enabled
and config.get().sourcemap.autogenerate,
optional = not (
config.get().platform.type == "roblox"
and config.get().sourcemap.enabled
and config.get().sourcemap.autogenerate
),
}
end

Expand Down

0 comments on commit 5e84736

Please sign in to comment.