Files
LazyVim/lua/lazyvim/plugins/extras/lang/ruby.lua
Kevin Robayna 7839498108 feat(extras): improve ruby extra by letting user chose (#3652)
## What is this PR for?

Shopify started working on its own LSP
(https://github.com/Shopify/ruby-lsp) and it performs way better than
Solargraph which has a lot of limitations. This paired with sorbet gives
better IntelliSense when navigating the code.

This PR follows the same approach as Python and lets the user configure
through vim.g options the lsp and formatter for ruby, without overriding
any configuration.

## Does this PR fix an existing issue?

One caveat though is that RubyLsp does not work very well with NeoVim <
0.10 https://github.com/Shopify/ruby-lsp/blob/main/EDITORS.md#neovim

## Checklist

- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
2024-07-19 11:09:57 +02:00

93 lines
2.1 KiB
Lua

if lazyvim_docs then
-- LSP Server to use for Ruby.
-- Set to "solargraph" to use solargraph instead of ruby_lsp.
vim.g.lazyvim_ruby_lsp = "ruby_lsp"
vim.g.lazyvim_ruby_formatter = "rubocop"
end
local lsp = vim.g.lazyvim_ruby_lsp or "ruby_lsp"
if vim.fn.has("nvim-0.10") == 0 then
-- ruby_lsp does not work well with Neovim < 0.10
lsp = vim.g.lazyvim_ruby_lsp or "solargraph"
end
local formatter = vim.g.lazyvim_ruby_formatter or "rubocop"
return {
recommended = function()
return LazyVim.extras.wants({
ft = "ruby",
root = "Gemfile",
})
end,
{
"nvim-treesitter/nvim-treesitter",
opts = { ensure_installed = { "ruby" } },
},
{
"neovim/nvim-lspconfig",
---@class PluginLspOpts
opts = {
---@type lspconfig.options
servers = {
ruby_lsp = {
enabled = lsp == "ruby_lsp",
},
solargraph = {
enabled = lsp == "solargraph",
},
rubocop = {
enabled = formatter == "rubocop",
},
standardrb = {
enabled = formatter == "standardrb",
},
},
},
},
{
"williamboman/mason.nvim",
opts = { ensure_installed = { "erb-formatter", "erb-lint" } },
},
{
"mfussenegger/nvim-dap",
optional = true,
dependencies = {
"suketa/nvim-dap-ruby",
config = function()
require("dap-ruby").setup()
end,
},
},
{
"stevearc/conform.nvim",
optional = true,
opts = {
formatters_by_ft = {
ruby = { formatter },
eruby = { "erb-format" },
},
},
},
{
"nvim-neotest/neotest",
optional = true,
dependencies = {
"olimorris/neotest-rspec",
},
opts = {
adapters = {
["neotest-rspec"] = {
-- NOTE: By default neotest-rspec uses the system wide rspec gem instead of the one through bundler
-- rspec_cmd = function()
-- return vim.tbl_flatten({
-- "bundle",
-- "exec",
-- "rspec",
-- })
-- end,
},
},
},
},
}