Skip to content

Commit 2c812ad

Browse files
committed
feat(lspinfo): print <cmd> --version result
1 parent 679d978 commit 2c812ad

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lua/lspconfig/health.lua

+18
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ local function remove_newlines(cmd)
3434
return cmd
3535
end
3636

37+
--- Finds a "x.y.z" version string from the output of `cmd`, and returns the whole line.
38+
---
39+
--- If a version string is not found, returns the concatenated output.
40+
---
41+
--- @param cmd string[]
42+
local function try_get_version(cmd)
43+
local out = vim.fn.system(cmd)
44+
if not out then
45+
return nil
46+
end
47+
local version_line = out:match('[^\r\n]+%d+%.[0-9.]+[^\r\n]+')
48+
local s = vim.trim(version_line and version_line or out:gsub('[\r\n]', ' '))
49+
return s
50+
end
51+
3752
--- Prettify a path for presentation.
3853
local function fmtpath(p)
3954
if vim.startswith(p, 'Running') then
@@ -104,10 +119,13 @@ local function make_config_info(config, bufnr)
104119
'Config: ' .. config_info.name,
105120
}
106121

122+
local cmd_version = { config_info.cmd, '--version' }
123+
107124
local info_lines = {
108125
'filetypes: ' .. config_info.filetypes,
109126
'root directory: ' .. fmtpath(config_info.root_dir),
110127
'cmd: ' .. fmtpath(config_info.cmd),
128+
('%-18s `%s`'):format('version:', try_get_version(cmd_version)),
111129
'cmd is executable: ' .. config_info.cmd_is_executable,
112130
'autostart: ' .. config_info.autostart,
113131
'custom handlers: ' .. config_info.handlers,

0 commit comments

Comments
 (0)