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

fix(rubocop) support projects that do not use bundler #2706

Merged
merged 1 commit into from
Jul 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lua/lspconfig/server_configurations/rubocop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ local util = require 'lspconfig.util'

return {
default_config = {
cmd = { 'bundle', 'exec', 'rubocop', '--lsp' },
cmd = { 'rubocop', '--lsp' },
filetypes = { 'ruby' },
root_dir = util.root_pattern('Gemfile', '.git'),
},
on_new_config = function(config, root_dir)
-- prepend 'bundle exec' to cmd if bundler is being used
local gemfile_path = util.path.join(root_dir, 'Gemfile')
if util.path.exists(gemfile_path) then
config.cmd = { 'bundle', 'exec', unpack(config.cmd) }
Copy link

@tradiff tradiff Jul 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gongfarmer @glepnir FYI, I believe this change has broken my use-case, which was working previously. I am now unable to override cmd.

I am in a rails app, so bundle is available. But the version of rubocop installed in my rails app does not have the lsp. I would like to use the globally installed version, which I was previously doing by overriding cmd:

  cmd = { "rubocop", "--lsp", },

But now this seems to not be possible. I have also tried overriding on_new_config, but my overridden function doesn't seem to replace the default one.

lspconfig.rubocop.setup({
  cmd = { "rubocop", "--lsp", },
  on_attach = on_attach,
  capabilities = capabilities,
  on_new_config = function (new_config, new_root_dir)
    -- noop
  end,
})

This shows up in the lsp log, suggesting the default on_new_config is still active.

[ERROR][2023-07-08 15:38:29] .../vim/lsp/rpc.lua:734	"rpc"	"bundle"	"stderr"	"invalid option: --lsp\nFor usage information, use --help\n"

Copy link

@tradiff tradiff Jul 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: I think I've figured this out. Providing my own on_new_config implementation doesn't override the default. Instead, both are executed. So I need to actually overwrite the effects of the default on_new_config.

My working configuration:

lspconfig.rubocop.setup({
  on_attach = on_attach,
  capabilities = capabilities,
  on_new_config = function (new_config, new_root_dir)
    new_config.cmd = { "rubocop", "--lsp", }
  end,
})

tradiff/dotfiles@8c7a862

end
end,
docs = {
description = [[
https://github.com/rubocop/rubocop
Expand Down