From 3c0915f57f443aa656d682db3df9d8f867c627ad Mon Sep 17 00:00:00 2001 From: Fraser Hanson Date: Fri, 7 Jul 2023 18:19:57 -0700 Subject: fix(rubocop): support projects that do not use bundler (#2706) Co-authored-by: Fraser Hanson --- lua/lspconfig/server_configurations/rubocop.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/lspconfig/server_configurations/rubocop.lua b/lua/lspconfig/server_configurations/rubocop.lua index 62817b8f..0d494326 100644 --- a/lua/lspconfig/server_configurations/rubocop.lua +++ b/lua/lspconfig/server_configurations/rubocop.lua @@ -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) } + end + end, docs = { description = [[ https://github.com/rubocop/rubocop -- cgit v1.3