neovim/nvim-lspconfig

lspconfig/health.lua

asfand0223 opened this issue ยท 4 comments

Description

In health.lua, in the try_fmt_version func, think i saw that 'version' was added for gopls, but now everything is using version so it causes a healthcheck error for lspconfig. Only thing I can do atm is remove 'version' so it uses '--version':

local function try_fmt_version(prog)
  local out = nil
  local cmd --[=[@type string[]]=]
  local tried = ''
  for _, v_arg in ipairs { 'version', '--version', '-v', '--help', '-h' } do
    cmd = { prog, v_arg }
    out = try_get_cmd_output(cmd)
    if out then
      break
    end
    tried = tried .. ('`%s %s`\n'):format(prog, v_arg)
  end

  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
  if out then
    return ('`%s` (output of `%s`)'):format(vim.trim(out:gsub('[\r\n]', ' ')) or '?', table.concat(cmd, ' '))
  end
  return '? Failed to get version from cmd. Tried:\n' .. tried
end

and then when this func is called on line 130:
('%-18s %s'):format('version:', try_fmt_version(config.cmd[1])),

this also breaks lspconfig healthcheck with error:
neovim:
ERROR Failed to run healthcheck for "lspconfig" plugin. Exception:
.../share/nvim/lazy/nvim-lspconfig/lua/lspconfig/health.lua:130: attempt to index field 'cmd' (a function value)

if i simply remove line 130, it fixes it. I think config is nil at that point or something, im kinda new to neovim so not too sure of the explanation really.

Checking git blame shows that the change was made yesterday, which is also when i noticed the error popped up.

Please get latest and try again, this should be fixed by #3388 . If not, please show the exact stacktrace or error message, or checkhealth output.

Same issue.
I have updated to commit fd49d58
When running :LazyInfo I get:

lspconfig: require("lspconfig.health").check()

LSP configs active in this session (globally) ~
- Configured servers: lua_ls, ts_ls, ruby_lsp
- OK Deprecated servers: (none)

LSP configs active in this buffer (bufnr: 1) ~
- Language client log: ~/.local/state/nvim/lsp.log
- Detected filetype: `lua`
- 3 client(s) attached to this buffer
- Client: GitHub Copilot (id: 1, bufnr: [1])
  filetypes:         
  cmd:               ~/.config/node /Users/hussein/.local/share/nvim/lazy/copilot.vim/dist/language-server.js --stdio
  version:           `v20.12.0`
  executable:        true
  autostart:         false
- Client: lua_ls (id: 2, bufnr: [1])
  filetypes:         lua
  cmd:               ~/.local/share/nvim/mason/bin/lua-language-server
  version:           `3.11.1`
  executable:        true
  autostart:         true
- ERROR Failed to run healthcheck for "lspconfig" plugin. Exception:
  .../share/nvim/lazy/nvim-lspconfig/lua/lspconfig/health.lua:127: attempt to index field 'cmd' (a function value)

When I comment out the line 127 in health.lua:

    ('%-18s %s'):format('version:', try_fmt_version(config.cmd[1])),

I get no errors

fixed in #3390

This has fixed it. Thank you for the quick response time and the fix!