aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-05-29 01:12:12 +0200
committerGitHub <noreply@github.com>2022-05-29 01:12:12 +0200
commit14060bf92d5a848930f4968d455922f5bafea813 (patch)
treefc0b1b0b2bc10fc289e62a20afb7f47c29b67d27 /lua/nvim-lsp-installer
parentfeat(ltex): use platform independent dist if java is installed (#730) (diff)
downloadmason-14060bf92d5a848930f4968d455922f5bafea813.tar
mason-14060bf92d5a848930f4968d455922f5bafea813.tar.gz
mason-14060bf92d5a848930f4968d455922f5bafea813.tar.bz2
mason-14060bf92d5a848930f4968d455922f5bafea813.tar.lz
mason-14060bf92d5a848930f4968d455922f5bafea813.tar.xz
mason-14060bf92d5a848930f4968d455922f5bafea813.tar.zst
mason-14060bf92d5a848930f4968d455922f5bafea813.zip
refactor(health): spawn processes via the spawn module (#732)
Diffstat (limited to 'lua/nvim-lsp-installer')
-rw-r--r--lua/nvim-lsp-installer/core/functional/init.lua2
-rw-r--r--lua/nvim-lsp-installer/core/functional/list.lua15
-rw-r--r--lua/nvim-lsp-installer/health/init.lua93
3 files changed, 58 insertions, 52 deletions
diff --git a/lua/nvim-lsp-installer/core/functional/init.lua b/lua/nvim-lsp-installer/core/functional/init.lua
index 8fb97450..6987e1a7 100644
--- a/lua/nvim-lsp-installer/core/functional/init.lua
+++ b/lua/nvim-lsp-installer/core/functional/init.lua
@@ -30,6 +30,8 @@ _.map = list.map
_.each = list.each
_.concat = list.concat
_.zip_table = list.zip_table
+_.nth = list.nth
+_.head = list.head
-- relation
local relation = require "nvim-lsp-installer.core.functional.relation"
diff --git a/lua/nvim-lsp-installer/core/functional/list.lua b/lua/nvim-lsp-installer/core/functional/list.lua
index 1fcfe8c3..c12330dd 100644
--- a/lua/nvim-lsp-installer/core/functional/list.lua
+++ b/lua/nvim-lsp-installer/core/functional/list.lua
@@ -100,4 +100,19 @@ _.zip_table = fun.curryN(function(keys, values)
return res
end, 2)
+---@generic T
+---@param offset number
+---@param value T[]|string
+---@return T|string|nil
+_.nth = fun.curryN(function(offset, value)
+ local index = offset < 0 and (#value + (offset + 1)) or offset
+ if type(value) == "string" then
+ return string.sub(value, index, index)
+ else
+ return value[index]
+ end
+end, 2)
+
+_.head = _.nth(1)
+
return _
diff --git a/lua/nvim-lsp-installer/health/init.lua b/lua/nvim-lsp-installer/health/init.lua
index e429185a..3de797bd 100644
--- a/lua/nvim-lsp-installer/health/init.lua
+++ b/lua/nvim-lsp-installer/health/init.lua
@@ -1,15 +1,11 @@
local health = require "health"
-local process = require "nvim-lsp-installer.core.process"
local a = require "nvim-lsp-installer.core.async"
local platform = require "nvim-lsp-installer.core.platform"
local github_client = require "nvim-lsp-installer.core.managers.github.client"
-local functional = require "nvim-lsp-installer.core.functional"
+local _ = require "nvim-lsp-installer.core.functional"
+local spawn = require "nvim-lsp-installer.core.spawn"
-local when = functional.when
-
-local gem_cmd = platform.is_win and "gem.cmd" or "gem"
-local composer_cmd = platform.is_win and "composer.bat" or "composer"
-local npm_cmd = platform.is_win and "npm.cmd" or "npm"
+local when = _.when
local M = {}
@@ -66,61 +62,58 @@ end
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()
- local _, stdio_pipes = process.spawn(opts.cmd, {
- args = opts.args,
- stdio_sink = stdio.sink,
- }, function(success)
- if success then
- local version = vim.split(
- table.concat(opts.use_stderr and stdio.buffers.stderr or stdio.buffers.stdout, ""),
- "\n"
- )[1]
+ local parse_version = _.compose(
+ _.head,
+ _.split "\n",
+ _.if_else(_.always(opts.use_stderr), _.prop "stderr", _.prop "stdout")
+ )
+ ---@async
+ return function()
+ local healthcheck_result = spawn[opts.cmd]({
+ opts.args,
+ on_spawn = function(_, stdio)
+ local stdin = stdio[1]
+ stdin:close() -- some processes (`sh` for example) will endlessly read from stdin, so we close it immediately
+ end,
+ })
+ :map(parse_version)
+ :map(function(version)
if opts.version_check then
local ok, version_check = pcall(opts.version_check, version)
if ok and version_check then
- callback(HealthCheck.new {
+ return HealthCheck.new {
result = "version-mismatch",
reason = version_check,
version = version,
name = opts.name,
relaxed = opts.relaxed,
- })
- return
+ }
elseif not ok then
- callback(HealthCheck.new {
+ return HealthCheck.new {
result = "parse-error",
version = "N/A",
name = opts.name,
relaxed = opts.relaxed,
- })
- return
+ }
end
end
- callback(HealthCheck.new {
+ return HealthCheck.new {
result = "success",
version = version,
name = opts.name,
relaxed = opts.relaxed,
- })
- else
- callback(HealthCheck.new {
- result = "not-available",
- version = nil,
- name = opts.name,
- relaxed = opts.relaxed,
- })
- end
- end)
+ }
+ end)
+ :get_or_else(HealthCheck.new {
+ result = "not-available",
+ version = nil,
+ name = opts.name,
+ relaxed = opts.relaxed,
+ })
- if stdio_pipes then
- -- Immediately close stdin to avoid leaving the process waiting for input.
- local stdin = stdio_pipes[1]
- stdin:close()
- end
+ callback(healthcheck_result)
end
end
end
@@ -143,7 +136,7 @@ function M.check()
end
))
- local checks = functional.list_not_nil(
+ local checks = _.list_not_nil(
check {
cmd = "go",
args = { "version" },
@@ -161,11 +154,11 @@ function M.check()
check { cmd = "cargo", args = { "--version" }, name = "cargo", relaxed = true },
check { cmd = "luarocks", args = { "--version" }, name = "luarocks", relaxed = true },
check { cmd = "ruby", args = { "--version" }, name = "Ruby", relaxed = true },
- check { cmd = gem_cmd, args = { "--version" }, name = "RubyGem", relaxed = true },
- check { cmd = composer_cmd, args = { "--version" }, name = "Composer", relaxed = true },
+ check { cmd = "gem", args = { "--version" }, name = "RubyGem", relaxed = true },
+ check { cmd = "composer", args = { "--version" }, name = "Composer", relaxed = true },
check { cmd = "php", args = { "--version" }, name = "PHP", relaxed = true },
check {
- cmd = npm_cmd,
+ cmd = "npm",
args = { "--version" },
name = "npm",
version_check = function(version)
@@ -222,15 +215,11 @@ function M.check()
-- 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(5000, function()
- return completed >= #checks
- end, 50)
-
a.run_blocking(function()
+ for _, c in ipairs(checks) do
+ c()
+ end
+
github_client.fetch_rate_limit()
:map(
---@param rate_limit GitHubRateLimitResponse