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

LspInfo: "Failed to get version" with bash-language-server #3453

Open
yb66 opened this issue Nov 25, 2024 · 9 comments
Open

LspInfo: "Failed to get version" with bash-language-server #3453

yb66 opened this issue Nov 25, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@yb66
Copy link

yb66 commented Nov 25, 2024

Description

Hi there,

My bashls wasn't running, so I ran :LspInfo inside of Neovim with a shell file open, and got this back as part of the info:

version:           `?` (Failed to get version) Tried:
  `…/mason/bin/bash-language-server --version`
  `…/mason/bin/bash-language-server -version`
  `…/mason/bin/bash-language-server version`
  `…/mason/bin/bash-language-server --help`

I found it's because the recipient is reading STDERR output too, and if there's anything coming through on STDERR then it chokes:

$ ./mason/bin/bash-language-server --version
5.4.2
(node:51440) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

This line is where the server is started:

I replaced:

cmd = { 'bash-language-server', 'start' },

with:

cmd = { 'sh', '-c', 'bash-language-server start 2>/dev/null' },

and it's fixed.

I'd put in a pull request but this is just a workaround and it'd probably be better if STDERR wasn't read (or was handled), but I've no idea about this codebase and any further effects this may have, so this is an FYI.

Regards,
iain

@yb66 yb66 added the bug Something isn't working label Nov 25, 2024
@lithammer
Copy link
Collaborator

This seems like a pretty safe change to me. To my knowledge, no command-line tool should output the version to stderr. It just doesn't make sense.

diff --git a/lua/lspconfig/health.lua b/lua/lspconfig/health.lua
index 5f40b1a..826d530 100644
--- a/lua/lspconfig/health.lua
+++ b/lua/lspconfig/health.lua
@@ -48,9 +48,7 @@ local function try_get_cmd_output(cmd)
   local chanid = vim.fn.jobstart(cmd, {
     -- cwd = ?,
     stdout_buffered = true,
-    stderr_buffered = true,
     on_stdout = on_data,
-    on_stderr = on_data,
   })
   local rv = vim.fn.jobwait({ chanid }, 300)
   vim.fn.jobstop(chanid)

@justinmk
Copy link
Member

This seems like a pretty safe change to me. To my knowledge, no command-line tool should output the version to stderr.

Capture stderr is mostly to have something to show on failure. It shouldn't cause the logic to fail. If 5.4.2 is printed, this logic should see it and treat it as "success":

local v_line = out and out:match('[^\r\n]*%d+%.[0-9.]+[^\r\n]*') or nil
if v_line then
return ('`%s`'):format(vim.trim(v_line))
end

Can someone using bash-language-server troubleshoot that logic and find out why it's not captured 5.4.2 ?

@lithammer
Copy link
Collaborator

lithammer commented Nov 25, 2024

Hmm, it seems to work just fine for me 🤔 Maybe related to a specific version of Neovim?

$ nvim --version
NVIM v0.11.0-dev-1228+g9e7b0bcf51-Homebrew
Build type: Release
LuaJIT 2.1.1731601260
Run "nvim -V1 -v" for more info
$ bash-language-server --version
5.4.2
(node:97079) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

(copied the relevant code to its own script)

$ cat bug.lua
local function try_get_cmd_output(cmd)
  local out = nil
  local function on_data(_, data, _)
    out = (out or '') .. table.concat(data, '\n')
  end
  local chanid = vim.fn.jobstart(cmd, {
    -- cwd = ?,
    stdout_buffered = true,
    stderr_buffered = true,
    on_stdout = on_data,
    on_stderr = on_data,
  })
  local rv = vim.fn.jobwait({ chanid }, 300)
  vim.fn.jobstop(chanid)
  return rv[1] == 0 and out or nil
end

local function try_fmt_version(prog)
  local all = nil --- Collected output from all attempts.
  local tried = '' --- Attempted commands.
  for _, v_arg in ipairs { '--version', '-version', 'version', '--help' } do
    local cmd = { prog, v_arg }
    local out = try_get_cmd_output(cmd)
    all = out and ('%s\n%s'):format(all or '', out) or all
    local v_line = out and out:match('[^\r\n]*%d+%.[0-9.]+[^\r\n]*') or nil
    if v_line then
      return ('`%s`'):format(vim.trim(v_line))
    end
    tried = tried .. ('`%s %s`\n'):format(prog, v_arg)
  end

  all = all and vim.trim(all:sub(1, 80):gsub('[\r\n]', ' ')) .. '…' or '?'
  return ('`%s` (Failed to get version) Tried:\n%s'):format(all, tried)
end

print(try_fmt_version('bash-language-server'))
$ nvim -l bug.lua
`5.4.2`

@justinmk justinmk changed the title When bash-language-server LspInfo: "Failed to get version" with bash-language-server Nov 25, 2024
@justinmk
Copy link
Member

@yb66 what nvim -v are you using? And can you try the above script

@yb66

This comment has been minimized.

@yb66
Copy link
Author

yb66 commented Nov 26, 2024

Ah, I just noticed the bit about not hanging. Perhaps that could be emulated with a timer? I'll give that a go if you think there's any merit in this approach.

Regards,
iain

@justinmk
Copy link
Member

justinmk commented Nov 26, 2024

NVIM v0.10.1

The latest stable version is 0.10.2

is there a reason why vim.system isn't used?

Because nvim-lspconfig still supports Nvim 0.9

Ah, I just noticed the bit about not hanging. Perhaps that could be emulated with a timer?

Can you instead try Nvim 0.11 https://github.com/neovim/neovim/releases/tag/nightly to see if the issue is fixed there?

@TSmigielski
Copy link

TSmigielski commented Nov 26, 2024

I seem to be having the same exact issue, but with arduino_language_server. It at all doesn't have a version flag (there's a PR for it arduino/arduino-language-server/issues/196), which results in this in LspInfo (I've replaced full paths with "...").

LSP configs active in this buffer (bufnr: 1)
- Language client log: ~/.local/state/nvim/lsp.log
- Detected filetype: arduino
- 0 client(s) attached to this buffer
- Other clients that match the "arduino" filetype:
- Config: arduino_language_server
  filetypes:         arduino
  cmd:               ~/.local/share/nvim/mason/bin/arduino-language-server
  version:           Usage of .../.local/share/nvim/mason/bin/arduino-language-se… (Failed to get version) Tried:
  .../arduino-language-server --version
  .../arduino-language-server -version
  .../arduino-language-server version
  .../arduino-language-server --help

  executable:        true
  autostart:         true
  root directory:    [Path to project]

And this odd log, it was written to stderr, but looks like a "normal level" log to me.

[ERROR][2024-11-26 21:32:27] .../vim/lsp/rpc.lua:770	"rpc"	".../arduino-language-server"	"stderr"	"21:32:26.990967 ArduinoCLI config file found at .../.arduino15/arduino-cli.yaml\n21:32:26.990995 arduino-cli found at /usr/bin/arduino-cli\n21:32:26.991002 clangd found at .../.local/share/nvim/mason/bin/clangd\n21:32:26.991045 \27[97mLS: : Initial board configuration: \27[0m\n21:32:26.991049 \27[97mLS: : arduino-language-server Version: 0.7.6 Commit: 9c2f44d Date: 2024-02-06T14:12:58Z\27[0m\n21:32:26.991055 \27[97mLS: : Language server temp directory: /tmp/arduino-language-server2355612588\27[0m\n21:32:26.991057 \27[97mLS: : Language server build path: /tmp/arduino-language-server2355612588/build\27[0m\n21:32:26.991058 \27[97mLS: : Language server build sketch root: /tmp/arduino-language-server2355612588/build/sketch\27[0m\n21:32:26.991060 \27[97mLS: : Language server FULL build path: /tmp/arduino-language-server2355612588/fullbuild\27[0m\n21:32:26.991740 IN Elapsed: 596.601µs\n21:32:26.991817 \27[92mIDE --> LS REQU initialize 1\27[0m\n"

I'm using the latest stable version of everything (meaning, mason, lsp stuff, nvim, this LSP). For Nvim this means 0.10.2 (I also tried the nightly build which I compiled locally today from (neovim/neovim/commit/66bb1e5), but the same exact thing has happened).

This has never worked for me, as I'm just getting started with arduino, and just today tried to set everything up. I am also not sure which side is at fault here, but I've found this issue, which seems related.

As a side note, all other LSPs I'm using (roslyn, svelte-language-server, and lua_language_server) work as expected.

@yb66
Copy link
Author

yb66 commented Nov 27, 2024

Can you instead try Nvim 0.11 https://github.com/neovim/neovim/releases/tag/nightly to see if the issue is fixed there?

$ nvim -v
NVIM v0.11.0-dev-1238+g66bb1e577c
Build type: RelWithDebInfo
LuaJIT 2.1.1731601260
Run "nvim -V1 -v" for more info

$ nvim -l bug.lua
`?` (Failed to get version) Tried:
`bash-language-server --version`
`bash-language-server -version`
`bash-language-server version`
`bash-language-server --help`

$ nvim -l fix.lua
`5.4.2`

I had the same result with v0.10.2. I've also added a line in bug.lua to add Mason's bin where bash-language-server is installed to the PATH Neovim is using, and run it without that line, both ways produce the same result so it's not a path issue.

Regards,
iain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants