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

Client fails with default Lazyvim config #2347

Closed
ogirginc opened this issue Jul 23, 2024 · 15 comments
Closed

Client fails with default Lazyvim config #2347

ogirginc opened this issue Jul 23, 2024 · 15 comments
Assignees
Labels
bug Something isn't working

Comments

@ogirginc
Copy link

Description

According to docs, there shouldn't be a need for any configuration when Lazyvim is used. However, that's not the case for me.

Reproduction steps

  1. Open Neovim.
  2. Open any Ruby file.
  3. ruby-lsp will fail.
Client ruby_lsp quit with exit code 1 and signal 0. Check log for errors: /Users/ogirginc/.local/state/nvim/lsp. log

Error message

[ERROR][2024-07-23 21:42:35] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/ogirginc/.local/share/nvim/mason/bin/ruby-lsp"	"stderr"	"/Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `require': linked to incompatible /Users/ogirginc/.asdf/installs/ruby/3.3.0/lib/libruby.3.3.dylib - /Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp/gems/prism-0.30.0/lib/prism/prism.bundle (LoadError)\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'\n\tfrom /Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp/gems/prism-0.30.0/lib/prism.rb:78:in `<top (required)>'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'\n\tfrom /Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp/gems/ruby-lsp-0.17.8/lib/ruby_lsp/internal.rb:19:in `<top (required)>'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'\n\tfrom /Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp/gems/ruby-lsp-0.17.8/exe/ruby-lsp:82:in `<top (required)>'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/bin/ruby-lsp:25:in `load'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/bin/ruby-lsp:25:in `<top (required)>'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli/exec.rb:58:in `load'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli/exec.rb:58:in `kernel_load'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli/exec.rb:23:in `run'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli.rb:455:in `exec'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli.rb:35:in `dispatch'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli.rb:29:in `start'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/exe/bundle:28:in `block in <top (required)>'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/exe/bundle:20:in `<top (required)>'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/bin/bundle:25:in `load'\n\tfrom /Users/ogirginc/.asdf/installs/ruby/3.3.4/bin/bundle:25:in `<main>'\n"

Versions

ruby -v #=>ruby 3.3.4 (2024-07-09 revision be1089c8ec) [arm64-darwin23]
ruby-lsp -v #=> 0.17.8
nvim -v #=> NVIM v0.10.0
lazyvim #=> [12.36.0](https://github.com/LazyVim/LazyVim/compare/v12.35.1...v12.36.0) (2024-07-22)

@ogirginc ogirginc added the bug Something isn't working label Jul 23, 2024
@andyw8
Copy link
Contributor

andyw8 commented Jul 23, 2024

Just reformatting for easier reading:

[ERROR][2024-07-23 21:42:35] .../vim/lsp/rpc.lua:770 "rpc" "/Users/ogirginc/.local/share/nvim/mason/bin/ruby-lsp" "stderr"
"/Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `require': linked to incompatible
/Users/ogirginc/.asdf/installs/ruby/3.3.0/lib/libruby.3.3.dylib
 - /Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp/gems/prism-0.30.0/lib/prism/prism.bundle (LoadError)
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp/gems/prism-0.30.0/lib/prism.rb:78:in `<top (required)>'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp/gems/ruby-lsp-0.17.8/lib/ruby_lsp/internal.rb:19:in `<top (required)>'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp/gems/ruby-lsp-0.17.8/exe/ruby-lsp:82:in `<top (required)>'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/bin/ruby-lsp:25:in `load'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/bin/ruby-lsp:25:in `<top (required)>'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli/exec.rb:58:in `load'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli/exec.rb:58:in `kernel_load'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli/exec.rb:23:in `run'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli.rb:455:in `exec'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli.rb:35:in `dispatch'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli.rb:29:in `start'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/exe/bundle:28:in `block in <top (required)>'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/exe/bundle:20:in `<top (required)>'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/bin/bundle:25:in `load'
    from /Users/ogirginc/.asdf/installs/ruby/3.3.4/bin/bundle:25:in `<main>'\n"

@andyw8
Copy link
Contributor

andyw8 commented Jul 23, 2024

@ogirginc could you verify that gem install prism succeeds?

@ogirginc
Copy link
Author

Just did a

> gem install prism
Building native extensions. This could take a while...
Successfully installed prism-0.30.0
Parsing documentation for prism-0.30.0
Done installing documentation for prism after 1 seconds
1 gem installed

and follow the steps, bug got the error below:

[ERROR][2024-07-23 22:09:21] .../vim/lsp/rpc.lua:770 "rpc" "/Users/ogirginc/.local/share/nvim/mason/bin/ruby-lsp" "stderr"
"/Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `require': linked to incompatible /Users/ogirginc/.asdf/installs/ruby/3.3.0/lib/libruby.3.3.dylib
 - /Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp/gems/prism-0.30.0/lib/prism/prism.bundle (LoadError)
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
   from /Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp/gems/prism-0.30.0/lib/prism.rb:78:in `<top (required)>'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
   from /Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp/gems/ruby-lsp-0.17.8/lib/ruby_lsp/internal.rb:19:in `<top (required)>'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
   from /Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp/gems/ruby-lsp-0.17.8/exe/ruby-lsp:82:in `<top (required)>'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/bin/ruby-lsp:25:in `load'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/bin/ruby-lsp:25:in `<top (required)>'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli/exec.rb:58:in `load'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli/exec.rb:58:in `kernel_load'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli/exec.rb:23:in `run'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli.rb:455:in `exec'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli.rb:35:in `dispatch'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/cli.rb:29:in `start'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/exe/bundle:28:in `block in <top (required)>'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/exe/bundle:20:in `<top (required)>'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/bin/bundle:25:in `load'
   from /Users/ogirginc/.asdf/installs/ruby/3.3.4/bin/bundle:25:in `<main>'\n"

@andyw8
Copy link
Contributor

andyw8 commented Jul 23, 2024

Thanks. This seem to relate to your Ruby installation. Could you try gem uninstall prism, and remove all versions, then try Ruby LSP again?

@ogirginc
Copy link
Author

Things I have tried but failed:

  1. Uninstalled every Prism gem version.
  2. Open a file & got same error.

  1. Install prism gem.
  2. Open a file & got same error.

  1. Uninstalled every Prism & ruby-lsp gems.
  2. Open a file.
  3. Mason auto-installs the latest ruby-lsp.
  4. Quit Neovim & reopen it.
  5. Open a file & got same error.

  1. Done a asdf reshim.
  2. Open a file & got same error.

  1. asdf uninstall ruby 3.3.4
  2. asdf install ruby 3.3.4
  3. Check prism version #=> 0.19.0
  4. Install ruby-lsp v0.17.9 through CLI.
  5. Confirm mason & neovim can see ruby-lsp
  6. Open a file & got same error.

@vinistock
Copy link
Member

Are you launching the Ruby LSP using ASDF's shim for selecting the correct Ruby version? This is documented in the important note for all editors https://github.com/Shopify/ruby-lsp/blob/main/EDITORS.md#editors.

@ogirginc
Copy link
Author

Are you launching the Ruby LSP using ASDF's shim for selecting the correct Ruby version? This is documented in the important note for all editors main/EDITORS.md#editors.

I am not sure if I understood the setup process, but before opening this ticket, I have tried some things that I couldn't remember. However, here is what did after your comment:

  1. Checked the :LspInfo
Screenshot 2024-07-24 at 21 08 01
  1. Inspect /Users/ogirginc/.local/share/nvim/mason/bin/ruby-lsp
#!/usr/bin/env bash
export GEM_PATH="/Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp:$GEM_PATH"
exec /Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp/bin/ruby-lsp "$@"
  1. It looked odd, so I have tried configuring "neovim/nvim-lspconfig":
return {
  {
    "neovim/nvim-lspconfig",
    opts = {
      diagnostics = {
        underline = false,
        virtual_text = false,
      },
      servers = {
        ruby_ls = {
          -- cmd = { "asdf", "exec", "ruby-lsp" },
          cmd = { "~/.asdf/shims/ruby-lsp" },
          filetypes = { "ruby" },
          root_dir = require("lspconfig.util").root_pattern("Gemfile", ".git"),
        },
      },
    },
  },
}
  1. Both cmd = { "asdf", "exec", "ruby-lsp" } and cmd = { "~/.asdf/shims/ruby-lsp" } did not change the outcome on :LspInfo

  2. As a last resort, I have updated the file like this, but again it did not change the outcome on :LspInfo

#!/usr/bin/env bash
export GEM_PATH="/Users/ogirginc/.local/share/nvim/mason/packages/ruby-lsp:$GEM_PATH"
exec /Users/ogirginc/.asdf/shims/ruby-lsp "$@"

@adam12
Copy link
Contributor

adam12 commented Jul 24, 2024

Commented in Slack thread, but for visibility, I believe this is because Mason doesn't consider the Ruby ABI when installing Ruby LSP servers, and in this case, the native extensions in Prism were linked to a version of Ruby that differs from the one being currently invoked.

I use Mason for managing LSP's in my Neovim configuration, but I do not use it to manage any Ruby LSPs. I generally want the version of Standard / Rubocop that ships with a project via Gemfile, but if not, I just install it as a regular gem inside the environment with the Ruby version I am using.

ogirginc added a commit to ogirginc/dotfiles that referenced this issue Jul 25, 2024
To fix lsp client failing;

- Disable Mason's auto install for ruby_lsp.
- Explicit enable for ruby_lsp.
- Specify the command to start the lsp client.

Shopify/ruby-lsp#2347
@ogirginc
Copy link
Author

Thank you all! Following @adam12's comment, I was able to fix this issue like below:

return {
  {
    "neovim/nvim-lspconfig",
      servers = {
        ruby_lsp = {
          mason = false,
          enabled = true,
          cmd = { "/Users/ogirginc/.asdf/shims/ruby-lsp" },
        },
      },
    },
  },
}

@andyw8
Copy link
Contributor

andyw8 commented Jul 30, 2024

I'd like to document this if possible, could you check some things for me please @ogirginc:

  • Does it work without enabled = true? (I understand RubyLSP is enabled by default for the latest LazyVim).
  • Does it work with a relative path for cmd, e.g. "~/.asdf/shims/ruby-lsp"

@ogirginc
Copy link
Author

ogirginc commented Aug 1, 2024

I'd like to document this if possible, could you check some things for me please @ogirginc:

Of course, & thank you for your work! :)

Does it work without enabled = true? (I understand RubyLSP is enabled by default for the latest LazyVim).

It does work. However, I wanted to explicitly set it, so I won't forget and get confused by mason = false later on. 😅

Does it work with a relative path for cmd, e.g. "~/.asdf/shims/ruby-lsp"

Unfortunately, it does not work. I have also tried cmd = { "bundle", "exec", "ruby-lsp" }, but it did not work either.

@andyw8
Copy link
Contributor

andyw8 commented Aug 1, 2024

Thank you

joshukraine added a commit to joshukraine/dotfiles that referenced this issue Aug 5, 2024
- The problem apparently is that Mason does not play nicely with version
managers like asdf, rbenv, etc.
- On an initial Ruby version, it will work fine. But install a new
version of Ruby, and Mason will still try to run ruby_lsp using the old
version.
- Shopify/ruby-lsp#2347
-
ogirginc/dotfiles@2d83daa
- https://github.com/Shopify/ruby-lsp/blob/main/EDITORS.md
@willian
Copy link

willian commented Aug 7, 2024

Unfortunately, it does not work. I have also tried cmd = { "bundle", "exec", "ruby-lsp" }, but it did not work either.

You can try this:

return {
  {
    "neovim/nvim-lspconfig",
      servers = {
        ruby_lsp = {
          mason = false,
          enabled = true,
          cmd = { os.getenv("HOME") .. "/.asdf/shims/ruby-lsp" },
        },
      },
    },
  },
}

@ogirginc
Copy link
Author

ogirginc commented Aug 8, 2024

I think I am OK with hardcoding, but wasn't aware of such an API in Lua! Thank you for sharing :)

@adipasquale
Copy link

adipasquale commented Aug 25, 2024

Thank you for this useful thread! I’m just learning LazyVim and had a hard time getting ruby-lsp to work together with rbenv. I had to slightly tweak the suggested config by wrapping the servers in an opts key :

-- ~/.config/nvim/lua/plugins/nvim-lspconfig.lua
return {
  "neovim/nvim-lspconfig",
  opts = {
    servers = {
      ruby_lsp = {
        mason = false,
        cmd = { vim.fn.expand("~/.rbenv/shims/ruby-lsp") },
      },
    },
  },
}

Maybe I should be storing this lua config file in another place ? Thanks anyways!

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

7 participants