diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2026-04-19 18:11:34 +0200 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2026-04-20 02:31:09 +0200 |
| commit | ea45e6f6ba5ead412053285ca3737bca6ce273f4 (patch) | |
| tree | 774132fefe42cb6ea3fd68d311dd79c49ec2cac5 /runtime/lua | |
| parent | 754232386529d031f3925007ead3e84a03fa6404 (diff) | |
fix(health): workaround nil vim.system():wait() result
Workaround until https://github.com/neovim/neovim/issues/37922 is fixed.
Diffstat (limited to 'runtime/lua')
| -rw-r--r-- | runtime/lua/vim/health/health.lua | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/runtime/lua/vim/health/health.lua b/runtime/lua/vim/health/health.lua index a744f1b750..74cad281ac 100644 --- a/runtime/lua/vim/health/health.lua +++ b/runtime/lua/vim/health/health.lua @@ -3,10 +3,14 @@ local health = require('vim.health') ---Run a system command and return ok and its stdout and stderr combined. ---@param cmd string[] +---@param timeout? integer Timeout in ms (default: no timeout). ---@return boolean ---@return string -local function system(cmd) - local result = vim.system(cmd, { text = true }):wait() +local function system(cmd, timeout) + local result = vim.system(cmd, { text = true, timeout = timeout }):wait() + if not result then -- Workaround https://github.com/neovim/neovim/issues/37922 + return false, 'command failed' + end return result.code == 0, vim.trim(('%s\n%s'):format(result.stdout, result.stderr)) end @@ -551,21 +555,15 @@ end ---@param nvim_version string local function check_stable_version(nvim_version) - local result = vim - .system( - { 'git', 'ls-remote', '--tags', 'https://github.com/neovim/neovim' }, - { text = true, timeout = 5000 } - ) - :wait() - if result.code ~= 0 or not result.stdout or result.stdout == '' then + local ok, output = + system({ 'git', 'ls-remote', '--tags', 'https://github.com/neovim/neovim' }, 5000) + if not ok or output == '' then return end local stable_sha = assert( - result.stdout:match('(%x+)%s+refs/tags/stable%^{}') - or result.stdout:match('(%x+)%s+refs/tags/stable\n') + output:match('(%x+)%s+refs/tags/stable%^{}') or output:match('(%x+)%s+refs/tags/stable\n') ) - local latest_version = - assert(result.stdout:match(stable_sha .. '%s+refs/tags/v?(%d+%.%d+%.%d+)%^{}')) + local latest_version = assert(output:match(stable_sha .. '%s+refs/tags/v?(%d+%.%d+%.%d+)%^{}')) local current_version = assert(nvim_version:match('v?(%d+%.%d+%.%d+)')) local current = vim.version.parse(current_version) local latest = vim.version.parse(latest_version) @@ -578,18 +576,16 @@ end ---@param commit string local function check_head_hash(commit) - local result = vim - .system( - { 'git', 'ls-remote', 'https://github.com/neovim/neovim', 'HEAD', 'refs/tags/nightly' }, - { text = true, timeout = 5000 } - ) - :wait() - if result.code ~= 0 or not result.stdout or result.stdout == '' then + local ok, output = system( + { 'git', 'ls-remote', 'https://github.com/neovim/neovim', 'HEAD', 'refs/tags/nightly' }, + 5000 + ) + if not ok or output == '' then return end local refs = {} ---@type table<string, string> - for line in result.stdout:gmatch('[^\n]+') do + for line in output:gmatch('[^\n]+') do local sha, ref = line:match('^(%x+)%s+(%S+)$') if sha and ref then refs[ref] = sha |
