Trouble overriding the rubocop nvim-lspconfig cmd to add bundler

Hi there,

I’m running into an issue with the rubocop LSP due to this error:

[ERROR][2024-05-21 14:41:14] .../vim/lsp/rpc.lua:770	"rpc"	"bundle"	"stderr"	"[server] Format request arrived before text synchronized; skipping: file:...

I’ve enabled vim.lsp.set_log_level("debug") and the LSP server is responding to all of the calls correctly, but my best guess is the replies are coming back either too fast or too slow :slight_smile: .

This happens on every edit to any file using this LSP and therefore all of the LSP replies are ignored.

Here is my LSP config for this using LazyVim and setting this up in the autocmds.lua:

vim.opt.signcolumn = "yes"
vim.api.nvim_create_autocmd("FileType", {
  pattern = "ruby",
  callback = function()
    vim.lsp.start({
      name = "rubocop",
      cmd = { "bundle", "exec", "rubocop", "--lsp" },
    })
  end,
})

vim.api.nvim_create_autocmd("BufWritePre", {
  pattern = "*.rb",
  callback = function()
    vim.lsp.buf.format()
  end,
})

I’m hoping someone here can give me some other ideas on how to troubleshoot this as I’m out of ideas.

Thanks!
Tom

I think the above issue may have been caused by the wrong Ruby (aka neovim-ruby-host). I resolved this by setting the same global ruby as my project ruby (using asdf).

The rubocop LSP is working now, but it is not running via bundle exec and is ignoring my project .rubocop.yml settings.

Here is my current failed attempt to override the cmd (via a LazyVim plugin):

local util = require("lspconfig").util

return {
  "neovim/nvim-lspconfig",
  opts = {
    servers = {
      rubocop = {
        -- See: https://docs.rubocop.org/rubocop/usage/lsp.html
        cmd = { "bundle", "exec", "rubocop", "--lsp" },
        -- filetypes = "ruby",
        root_dir = util.root_pattern("Gemfile", ".git"),
      },
    },
  },
}

The cmd is set properly when viewing the LspInfo, but the rubocop LSP results only briefly show and disappear immediately. If anyone has a working example of setting rubocop LSP to run via bundle exec, or tips for customizing the LSP cmd like this, I’d appreciate it.

The only way i managed to get work with bundler is using neovim 0.9.5 (installed with bob).

On the 0.10 it just doesn´t work with bundler

      lspconfig.rubocop.setup({
        capabilities = lsp_capabilities,
        cmd = { "bundle", "exec", "rubocop", "--lsp" },
      })

Just did this on rubocop and this on solargraph:

      lspconfig.solargraph.setup({
        capabilities = lsp_capabilities,
        on_attach = function(client)
          client.server_capabilities.documentFormattingProvider = false
        end,
        settings = {
          solargraph = {
            formatting = false,
            autoformat = false,
            useBundler = true,
            diagnostics = false,
          },
        },
      })