nvim-lspconfig icon indicating copy to clipboard operation
nvim-lspconfig copied to clipboard

Prefer Solargraph from bundle, then fall back to the global Solargraph

Open michaelfranzl opened this issue 3 years ago • 10 comments

Language server

solargraph

Requested feature

Some Ruby applications have Solargraph integrated via Bundler (e.g. added to the applications' Gemfile). In that case, Solargraph should be executed as bundle exec solargraph stdio, and not as solargraph stdio so that Solargraph can additionally report formatting issues using the applications' own configuration (e.g. Rubocop).

This could be implemented as a fallback: If Solargraph is in the Gemfile, then use it, otherwise fall back to the globally installed Solargraph.

Other clients which have this feature

No response

michaelfranzl avatar May 03 '22 15:05 michaelfranzl

Is there a convenient way lookup that up besides manually searching through the Gemfile for something like ^\s*gem 'solargraph'?

lithammer avatar May 03 '22 15:05 lithammer

A good heuristic would be to search Gemfile.lock for ^\s*solargraph (because with Bundler, there is always an automatically generated Gemfile.lock).

michaelfranzl avatar May 04 '22 07:05 michaelfranzl

If using bundle is a option:

❯ bundle info solargraph
Could not find gem 'solargraph'.
❯ echo $status
7
❯ bundle info colorize # some other gem that is installed
  * colorize (0.8.1)
        Summary: Ruby gem for colorizing text using ANSI escape sequences.
        Homepage: http://github.com/fazibear/colorize
        Path: /Users/david/.rvm/gems/ruby-2.7.6/gems/colorize-0.8.1
❯ echo $status
0

dgmora avatar Jun 26 '22 18:06 dgmora

What about

local solargraph_cmd = function()
  local ret_code = nil
  local jid = vim.fn.jobstart("bundle info solargraph", { on_exit = function(_, data) ret_code = data end })
  vim.fn.jobwait({ jid }, 5000)
  if ret_code == 0 then
    return { "bundle", "exec", "solargraph", "stdio" }
  end
  return { "solargraph", "stdio" }
end

alanoliveira avatar Aug 01 '22 15:08 alanoliveira

Is it possible to rely on the 'useBundler' configuration setting in solargraph's defaults? It's false by default, but if the user sets this to true, they obviously intend on adding solargraph to their gemfile. This was possible with COC, and it worked great.

I'm mostly ignorant to the challenges surrounding this from a neovim perspective, but this is the one LSP that I can't seem to get working due to it's sandbox environment. Any help would be appreciated.

AlanWarren avatar Oct 27 '22 22:10 AlanWarren

how can set to 'useBundler' configuration?

hui00 avatar Dec 24 '22 22:12 hui00

I have created a plugin that automatically prefixes Ruby LSP server commands with bundle exec. https://github.com/mihyaeru21/nvim-lspconfig-bundler

If many people want to use it, it might be a better idea to implement it in nvim-lspconfig itself.

mihyaeru21 avatar Jan 28 '23 15:01 mihyaeru21

I have created a plugin that automatically prefixes Ruby LSP server commands with bundle exec. https://github.com/mihyaeru21/nvim-lspconfig-bundler

If many people want to use it, it might be a better idea to implement it in nvim-lspconfig itself.

FYI, I was able to work around my issues by moving over to mason. The solargraph lsp is handled by a small wrapper script ( $HOME/.local/share/nvim/mason/bin/solargraph) which properly appends the mason solargraph gem location to $GEM_PATH before executing solargraph.

With this setup, solargraph is now capable of detecting plugins like the solargraph-rails gem, which was my original motivation for the useBundler flag.

Thank you though. I still plan on trying out your plugin, as it would be nice to have solargraph in my Gemfile.

AlanWarren avatar Jan 30 '23 18:01 AlanWarren

@mihyaeru21 came here looking for exactly what your plugin offers, thanks for putting it together! seems to me it could be useful in nvim-lsp itself

@AlanWarren do you know where that wrapper comes from? I'm not seeing it in my install or in the mason.nvim repo

technicalpickles avatar Feb 15 '23 15:02 technicalpickles

@mihyaeru21 came here looking for exactly what your plugin offers, thanks for putting it together! seems to me it could be useful in nvim-lsp itself

@AlanWarren do you know where that wrapper comes from? I'm not seeing it in my install or in the mason.nvim repo

Sure, i believe it's generated once you've installed solargraph LSP from the mason UI that you open inside of neovim.

Taking a look at ~/.local/share/nvim/mason/bin and I have symbolic links for each language server that i've installed. lua-language-server, typescript-language-server, solargraph, etc.

The solargraph (relative) symlink points to ../packages/solargraph/solargraph.

AlanWarren avatar Mar 06 '23 22:03 AlanWarren