Skip to content

Commit 701fd23

Browse files
author
Marc Jakobi
committed
fix(health): prevent false-positive rust-analyzer detections
1 parent c1d79cd commit 701fd23

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [4.21.2] - 2024-04-13
10+
11+
### Fixed
12+
13+
- Health: Report error if version check fails for a required
14+
external dependency. This should help with false positives
15+
when detecting `rust-analyzer` if the rustup wrapper is installed,
16+
but `rust-analyzer` isn't.
17+
918
## [4.21.1] - 2024-04-11
1019

1120
### Fixed

lua/rustaceanvim/health.lua

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,41 @@ local function check_lua_dependency(dep)
5454
end
5555

5656
---@param dep ExternalDependency
57-
---@return string|nil binary
58-
---@return string|nil version
57+
---@return boolean is_installed
58+
---@return string binary
59+
---@return string version
5960
local check_installed = function(dep)
6061
local binaries = dep.get_binaries()
6162
for _, binary in ipairs(binaries) do
62-
local is_installed = dep.is_installed or function(bin)
63+
local is_executable = dep.is_installed or function(bin)
6364
return vim.fn.executable(bin) == 1
6465
end
65-
if is_installed(binary) then
66+
if is_executable(binary) then
6667
local handle = io.popen(binary .. ' --version')
6768
if handle then
6869
local binary_version, error_msg = handle:read('*a')
6970
handle:close()
7071
if error_msg then
71-
return binary
72+
return false, binary, error_msg
7273
end
73-
return binary, binary_version
74+
return true, binary, binary_version
7475
end
75-
return binary
76+
return false, binary, 'Unable to determine version.'
7677
end
7778
end
79+
return false, binaries[1], 'Could not find an executable binary.'
7880
end
7981

8082
---@param dep ExternalDependency
8183
local function check_external_dependency(dep)
82-
local binary, version = check_installed(dep)
83-
if binary then
84+
local is_installed, binary, version_or_err = check_installed(dep)
85+
if is_installed then
8486
---@cast binary string
85-
local mb_version_newline_idx = version and version:find('\n')
86-
local mb_version_len = version and (mb_version_newline_idx and mb_version_newline_idx - 1 or version:len())
87-
version = version and version:sub(0, mb_version_len) or '(unknown version)'
88-
ok(('%s: found %s'):format(dep.name, version))
87+
local mb_version_newline_idx = version_or_err and version_or_err:find('\n')
88+
local mb_version_len = version_or_err
89+
and (mb_version_newline_idx and mb_version_newline_idx - 1 or version_or_err:len())
90+
version_or_err = version_or_err and version_or_err:sub(0, mb_version_len) or '(unknown version)'
91+
ok(('%s: found %s'):format(dep.name, version_or_err))
8992
if dep.extra_checks_if_installed then
9093
dep.extra_checks_if_installed(binary)
9194
end
@@ -99,10 +102,10 @@ local function check_external_dependency(dep)
99102
]]):format(dep.name, dep.url, dep.info))
100103
else
101104
error(([[
102-
%s: not found.
105+
%s: not found: %s
103106
rustaceanvim requires %s.
104107
%s
105-
]]):format(dep.name, dep.url, dep.info))
108+
]]):format(dep.name, version_or_err, dep.url, dep.info))
106109
end
107110
if dep.extra_checks_if_not_installed then
108111
dep.extra_checks_if_not_installed()

0 commit comments

Comments
 (0)