nvim-lspconfig
nvim-lspconfig copied to clipboard
Prefer Solargraph from bundle, then fall back to the global Solargraph
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
Is there a convenient way lookup that up besides manually searching through the Gemfile for something like ^\s*gem 'solargraph'?
A good heuristic would be to search Gemfile.lock for ^\s*solargraph (because with Bundler, there is always an automatically generated Gemfile.lock).
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
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
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.
how can set to 'useBundler' configuration?
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.
I have created a plugin that automatically prefixes Ruby LSP server commands with
bundle exec. https://github.com/mihyaeru21/nvim-lspconfig-bundlerIf many people want to use it, it might be a better idea to implement it in
nvim-lspconfigitself.
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.
@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
@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.