Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lspinfo): print "{cmd} --version", drop config.lspinfo #3375

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ body:
- type: markdown
attributes:
value: |
Do NOT file bugs in this repo. The configs in this repo are unsupported and provided only as a starting point. We depend on users (like you) to troubleshoot issues with their specific LSP setups and [send improvements](https://github.com/neovim/nvim-lspconfig/blob/master/CONTRIBUTING.md).
The configs in this repo are UNSUPPORTED and provided only as a starting point. We depend on users (like you) to troubleshoot issues with their specific LSP setups and [send improvements](https://github.com/neovim/nvim-lspconfig/blob/master/CONTRIBUTING.md).

If you have a feature request or found a bug in the core Nvim `vim.lsp` module (not this repo), [report it to Nvim](https://github.com/neovim/neovim/issues/new?assignees=&labels=bug%2Clsp&projects=&template=lsp_bug_report.yml).
- type: textarea
Expand Down
4 changes: 0 additions & 4 deletions doc/configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5592,10 +5592,6 @@ require'lspconfig'.hls.setup{}
```lua
{ "haskell", "lhaskell" }
```
- `lspinfo` :
```lua
see source file
```
- `root_dir` :
```lua
root_pattern("hie.yaml", "stack.yaml", "cabal.project", "*.cabal", "package.yaml")
Expand Down
4 changes: 0 additions & 4 deletions doc/configs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5592,10 +5592,6 @@ require'lspconfig'.hls.setup{}
```lua
{ "haskell", "lhaskell" }
```
- `lspinfo` :
```lua
see source file
```
- `root_dir` :
```lua
root_pattern("hie.yaml", "stack.yaml", "cabal.project", "*.cabal", "package.yaml")
Expand Down
16 changes: 0 additions & 16 deletions lua/lspconfig/configs/hls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@ return {
cabalFormattingProvider = 'cabalfmt',
},
},
lspinfo = function(cfg)
local extra = {}
local function on_stdout(_, data, _)
local version = data[1]
table.insert(extra, 'version: ' .. version)
end

local opts = {
cwd = cfg.cwd,
stdout_buffered = true,
on_stdout = on_stdout,
}
local chanid = vim.fn.jobstart({ cfg.cmd[1], '--version' }, opts)
vim.fn.jobwait { chanid }
return extra
end,
},

docs = {
Expand Down
23 changes: 18 additions & 5 deletions lua/lspconfig/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ local function remove_newlines(cmd)
return cmd
end

--- Finds a "x.y.z" version string from the output of `cmd`, and returns the whole line.
---
--- If a version string is not found, returns the concatenated output.
---
--- @param cmd string[]
local function try_get_version(cmd)
local out = vim.fn.system(cmd)
if not out then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not out then
if not out or vim.v.shell_error > 0 then

do we also need this condition 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it returns any output we'll just print it, regardless of error code

return nil
end
local version_line = out:match('[^\r\n]+%d+%.[0-9.]+[^\r\n]+')
local s = vim.trim(version_line and version_line or out:gsub('[\r\n]', ' '))
return s
end

--- Prettify a path for presentation.
local function fmtpath(p)
if vim.startswith(p, 'Running') then
Expand Down Expand Up @@ -104,10 +119,13 @@ local function make_config_info(config, bufnr)
'Config: ' .. config_info.name,
}

local cmd_version = { config_info.cmd, '--version' }

local info_lines = {
'filetypes: ' .. config_info.filetypes,
'root directory: ' .. fmtpath(config_info.root_dir),
'cmd: ' .. fmtpath(config_info.cmd),
('%-18s `%s`'):format('version:', try_get_version(cmd_version)),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print the cmd --version result automatically.

'cmd is executable: ' .. config_info.cmd_is_executable,
'autostart: ' .. config_info.autostart,
'custom handlers: ' .. config_info.handlers,
Expand Down Expand Up @@ -174,11 +192,6 @@ local function make_client_info(client, fname)
'autostart: ' .. client_info.autostart,
}

if client.config.lspinfo then
local server_specific_info = client.config.lspinfo(client.config)
info_lines = vim.list_extend(info_lines, server_specific_info)
end

vim.list_extend(lines, info_lines)

return table.concat(lines, '\n')
Expand Down
Loading