diff options
| author | William Boman <william@redwill.se> | 2021-12-07 20:15:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-07 20:15:03 +0100 |
| commit | 0fe8c254d90794f13860cbeac5e5987a081a8031 (patch) | |
| tree | b3a7c9239278baaaefa4274955f910adbb2ced94 /lua | |
| parent | fix(installers/npm): dont apply global-style for standalone npm install (diff) | |
| download | mason-0fe8c254d90794f13860cbeac5e5987a081a8031.tar mason-0fe8c254d90794f13860cbeac5e5987a081a8031.tar.gz mason-0fe8c254d90794f13860cbeac5e5987a081a8031.tar.bz2 mason-0fe8c254d90794f13860cbeac5e5987a081a8031.tar.lz mason-0fe8c254d90794f13860cbeac5e5987a081a8031.tar.xz mason-0fe8c254d90794f13860cbeac5e5987a081a8031.tar.zst mason-0fe8c254d90794f13860cbeac5e5987a081a8031.zip | |
initial healthcheck integration (#321)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-lsp-installer/health/init.lua | 118 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/composer.lua | 16 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/gem.lua | 4 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/init.lua | 1 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/npm.lua | 8 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/pip3.lua | 2 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/ui/status-win/init.lua | 13 |
7 files changed, 145 insertions, 17 deletions
diff --git a/lua/nvim-lsp-installer/health/init.lua b/lua/nvim-lsp-installer/health/init.lua new file mode 100644 index 00000000..29f7df7f --- /dev/null +++ b/lua/nvim-lsp-installer/health/init.lua @@ -0,0 +1,118 @@ +local health = require "health" +local process = require "nvim-lsp-installer.process" +local gem = require "nvim-lsp-installer.installers.gem" +local composer = require "nvim-lsp-installer.installers.composer" +local npm = require "nvim-lsp-installer.installers.npm" +local platform = require "nvim-lsp-installer.platform" +local Data = require "nvim-lsp-installer.data" + +local when = Data.when + +local M = {} + +---@alias HealthCheckResult +---| '"success"' +---| '"version-mismatch"' +---| '"not-installed"' + +---@class HealthCheck +---@field public result HealthCheckResult +---@field public version string|nil +---@field public name string +local HealthCheck = {} +HealthCheck.__index = HealthCheck + +function HealthCheck.new(props) + local self = setmetatable(props, HealthCheck) + return self +end + +---@param callback fun(result: HealthCheck) +local function mk_healthcheck(callback) + ---@param opts {cmd:string, args:string[], name: string, use_stderr:boolean} + return function(opts) + return function() + local stdio = process.in_memory_sink() + process.spawn(opts.cmd, { + args = opts.args, + stdio_sink = stdio.sink, + }, function(success) + if success then + local version = success + and vim.split( + table.concat(opts.use_stderr and stdio.buffers.stderr or stdio.buffers.stdout, ""), + "\n" + )[1] + or nil + + callback(HealthCheck.new { + result = "success", + version = version, + name = opts.name, + }) + else + callback(HealthCheck.new { + result = "not-installed", -- ... we assume + version = nil, + name = opts.name, + }) + end + end) + end + end +end + +function M.check() + health.report_start "nvim-lsp-installer report" + local completed = 0 + + local check = mk_healthcheck(vim.schedule_wrap( + ---@param healthcheck HealthCheck + function(healthcheck) + completed = completed + 1 + if healthcheck.result == "success" then + -- We report on info level because we don't verify version compatibility yet + health.report_info(("**%s**: `%s`"):format(healthcheck.name, healthcheck.version)) + elseif healthcheck.result == "version-mismatch" then + health.report_warn(("**%s**: version mismatch `%s`"):format(healthcheck.name, healthcheck.version)) + elseif healthcheck.result == "not-installed" then + health.report_error(("**%s**: not installed"):format(healthcheck.name)) + end + end + )) + + local checks = Data.list_not_nil( + check { cmd = "go", args = { "version" }, name = "Go" }, + check { cmd = "ruby", args = { "--version" }, name = "Ruby" }, + check { cmd = gem.gem_cmd, args = { "--version" }, name = "RubyGem" }, + check { cmd = composer.composer_cmd, args = { "--version" }, name = "Composer" }, + check { cmd = "php", args = { "--version" }, name = "PHP" }, + check { cmd = npm.npm_command, args = { "--version" }, name = "npm" }, + check { cmd = "node", args = { "--version" }, name = "node" }, + check { cmd = "python", use_stderr = true, args = { "--version" }, name = "python" }, + check { cmd = "python3", args = { "--version" }, name = "python3" }, + check { cmd = "javac", args = { "-version" }, name = "java" }, + check { cmd = "wget", args = { "--version" }, name = "wget" }, + check { cmd = "curl", args = { "--version" }, name = "curl" }, + check { cmd = "gzip", args = { "--version" }, name = "gzip", use_stderr = true }, + check { cmd = "tar", args = { "--version" }, name = "tar" }, + when( + vim.g.python3_host_prog, + check { cmd = vim.g.python3_host_prog, args = { "--version" }, name = "python3_host_prog" } + ), + when(platform.is_unix, check { cmd = "bash", args = { "--version" }, name = "bash" }), + when(platform.is_unix, check { cmd = "sh", args = { "--version" }, name = "sh" }) + -- when(platform.is_win, check { cmd = "powershell.exe", args = { "-Version" }, name = "PowerShell" }), -- TODO fix me + -- when(platform.is_win, check { cmd = "cmd.exe", args = { "-Version" }, name = "cmd" }) -- TODO fix me + ) + + for _, c in ipairs(checks) do + c() + end + + vim.wait(10000, function() + return completed >= #checks + end, 50) +end + +return M diff --git a/lua/nvim-lsp-installer/installers/composer.lua b/lua/nvim-lsp-installer/installers/composer.lua index a046575b..efb5038f 100644 --- a/lua/nvim-lsp-installer/installers/composer.lua +++ b/lua/nvim-lsp-installer/installers/composer.lua @@ -6,21 +6,21 @@ local std = require "nvim-lsp-installer.installers.std" local platform = require "nvim-lsp-installer.platform" local process = require "nvim-lsp-installer.process" -local composer = platform.is_win and "composer.bat" or "composer" +local M = {} + +M.composer_cmd = platform.is_win and "composer.bat" or "composer" ---@param installer ServerInstallerFunction local function ensure_composer(installer) return installers.pipe { std.ensure_executables { { "php", "php was not found in path. Refer to https://www.php.net/." }, - { composer, "composer was not found in path. Refer to https://getcomposer.org/download/." }, + { M.composer_cmd, "composer was not found in path. Refer to https://getcomposer.org/download/." }, }, installer, } end -local M = {} - ---@param packages string[] @The Gem packages to install. The first item in this list will be the recipient of the server version, should the user request a specific one. function M.packages(packages) return ensure_composer( @@ -32,8 +32,8 @@ function M.packages(packages) } if not (fs.file_exists(path.concat { context.install_dir, "composer.json" })) then - c.run(composer, { "init", "--no-interaction", "--stability=dev" }) - c.run(composer, { "config", "prefer-stable", "true" }) + c.run(M.composer_cmd, { "init", "--no-interaction", "--stability=dev" }) + c.run(M.composer_cmd, { "config", "prefer-stable", "true" }) end local pkgs = Data.list_copy(packages or {}) @@ -42,7 +42,7 @@ function M.packages(packages) pkgs[1] = ("%s:%s"):format(pkgs[1], context.requested_server_version) end - c.run(composer, vim.list_extend({ "require" }, pkgs)) + c.run(M.composer_cmd, vim.list_extend({ "require" }, pkgs)) c.spawn(callback) end ) @@ -52,7 +52,7 @@ function M.install() return ensure_composer( ---@type ServerInstallerFunction function(_, callback, context) - process.spawn(composer, { + process.spawn(M.composer_cmd, { args = { "install", "--no-interaction", diff --git a/lua/nvim-lsp-installer/installers/gem.lua b/lua/nvim-lsp-installer/installers/gem.lua index 727af496..a2e3945f 100644 --- a/lua/nvim-lsp-installer/installers/gem.lua +++ b/lua/nvim-lsp-installer/installers/gem.lua @@ -7,7 +7,7 @@ local platform = require "nvim-lsp-installer.platform" local M = {} -local gem = platform.is_win and "gem.cmd" or "gem" +M.gem_cmd = platform.is_win and "gem.cmd" or "gem" ---@param packages string[] @The Gem packages to install. The first item in this list will be the recipient of the server version, should the user request a specific one. function M.packages(packages) @@ -24,7 +24,7 @@ function M.packages(packages) pkgs[1] = ("%s:%s"):format(pkgs[1], context.requested_server_version) end - process.spawn(gem, { + process.spawn(M.gem_cmd, { args = { "install", "--no-user-install", diff --git a/lua/nvim-lsp-installer/installers/init.lua b/lua/nvim-lsp-installer/installers/init.lua index a04eeafb..25d97658 100644 --- a/lua/nvim-lsp-installer/installers/init.lua +++ b/lua/nvim-lsp-installer/installers/init.lua @@ -1,6 +1,7 @@ local platform = require "nvim-lsp-installer.platform" local log = require "nvim-lsp-installer.log" local Data = require "nvim-lsp-installer.data" +local process = require "nvim-lsp-installer.process" local fs = require "nvim-lsp-installer.fs" local path = require "nvim-lsp-installer.path" diff --git a/lua/nvim-lsp-installer/installers/npm.lua b/lua/nvim-lsp-installer/installers/npm.lua index b695a9b2..b0ae52eb 100644 --- a/lua/nvim-lsp-installer/installers/npm.lua +++ b/lua/nvim-lsp-installer/installers/npm.lua @@ -10,7 +10,7 @@ local list_copy = Data.list_copy local M = {} -local npm = platform.is_win and "npm.cmd" or "npm" +M.npm_command = platform.is_win and "npm.cmd" or "npm" ---@param installer ServerInstallerFunction local function ensure_npm(installer) @@ -56,7 +56,7 @@ local function create_installer(standalone) fs.file_exists(path.concat { ctx.install_dir, "package.json" })) then -- Create a package.json to set a boundary for where npm installs packages. - c.run(npm, { "init", "--yes", "--scope=lsp-installer" }) + c.run(M.npm_command, { "init", "--yes", "--scope=lsp-installer" }) end if not standalone and ctx.requested_server_version and #pkgs > 0 then @@ -65,7 +65,7 @@ local function create_installer(standalone) end -- stylua: ignore end - c.run(npm, vim.list_extend({ "install" }, pkgs)) + c.run(M.npm_command, vim.list_extend({ "install" }, pkgs)) c.spawn(callback) end ) @@ -99,7 +99,7 @@ function M.run(script) return ensure_npm( ---@type ServerInstallerFunction function(_, callback, ctx) - process.spawn(npm, { + process.spawn(M.npm_command, { args = { "run", script }, cwd = ctx.install_dir, stdio_sink = ctx.stdio_sink, diff --git a/lua/nvim-lsp-installer/installers/pip3.lua b/lua/nvim-lsp-installer/installers/pip3.lua index 4282bcc8..234aad98 100644 --- a/lua/nvim-lsp-installer/installers/pip3.lua +++ b/lua/nvim-lsp-installer/installers/pip3.lua @@ -54,7 +54,7 @@ function M.packages(packages) local py3_host_prog = vim.g.python3_host_prog if py3_host_prog then - log.fmt_debug("Found python3_host_prog (%s)", py3_host_prog) + log.fmt_trace("Found python3_host_prog (%s)", py3_host_prog) table.insert(installer_variants, 1, create_installer(py3_host_prog, packages)) end diff --git a/lua/nvim-lsp-installer/ui/status-win/init.lua b/lua/nvim-lsp-installer/ui/status-win/init.lua index 06f3f366..f1c6c7b0 100644 --- a/lua/nvim-lsp-installer/ui/status-win/init.lua +++ b/lua/nvim-lsp-installer/ui/status-win/init.lua @@ -79,10 +79,19 @@ local function Help(is_current_settings_expanded, vader_saber_ticks) { { "Problems installing/uninstalling servers", "LspInstallerLabel" } }, { { - "Make sure you meet the minimum requirements to install servers. For debugging, refer to ", + "Make sure you meet the minimum requirements to install servers. For debugging, refer to:", "LspInstallerMuted", }, - { ":help nvim-lsp-installer-debugging", "LspInstallerHighlighted" }, + }, + }, + Indent { + Ui.HlTextNode { + { + { ":help nvim-lsp-installer-debugging", "LspInstallerHighlighted" }, + }, + { + { ":checkhealth nvim-lsp-installer", "LspInstallerHighlighted" }, + }, }, }, Ui.EmptyLine(), |
