Open ctsstc opened 5 years ago
For now I switched my rvm over to the version the extension is running and installed the gems manually, but this isn't the greatest fix out there : \
If you're installing rubocop
in your app's bundle, maybe the PR I just opened (#91) can be of use to you too.
This is a very hacky solution, but its working well for me. I created this file in my projects bin directory:
bin/vscode_rubocop
#! /usr/bin/env bash -l
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/.."
cd "${DIR}"
rvm . do bin/rubocop "$@"
Then set the executePath
to bin/vscode_
, note the missing rubocop
on the end, thats because it gets automatically appended to the executePath
by the extension.
This assumes you have rubocop binstubbed.
@gokuu seems that I'm getting similar errors when I have that enabled. The runner seems to use rmv's system default rather than the directory version.
I'm back searching again, I'm back on a project that's not updated.
@gokuu when I use the new Use Bundler
it seems to be using the system default of rvm
so then I get an error like:
Bundler::RubyVersionMismatch: Your Ruby version is 2.6.2, but your Gemfile specified 2.6.3
If I try to explicitly point to rubocop with workspace settings via the Execute Path
I get:
/Users/codyswartz/.rvm/gems/ruby-2.6.3/bin/
env: ruby_executable_hooks: No such file or directory
Might be related: #50
Thanks @yelvert that seems to be the only solution I can get to work. I wish I could do this at a system level and not per-project, but other solutions I tried seemed to lack the context of the current environment/folder when nvm tries to determine which version to use.
Maybe the context you're utilizing could be implemented into the extension though to help it run in the proper context. I think part of it is having the login shell, and the other part is executing from the proper directory so that rvm can determine the proper version of ruby to run.
I ended up changing mine to use bundle exec
instead, since we don't have rubocop bin stubbed in this project [yet].
bin/vscode_rubocop
#! /usr/bin/env bash -l
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/.."
cd "${DIR}"
rvm . do bin/bundle exec rubocop "$@"
With workspace settings:
ruby.rubocop.executePath = bin/vscode_
Make sure to set the file as executable
chmod a+x bin/vscode_rubocop
I think I have found a more maintainable way to fix this among all the projects you have. On the settings set the Execute Path
(ruby.rubocop.executePath
) with the value rvm . do bin/bundle exec
(with a space character at the end). Just that, is really easy. 👌
@limcross tried your solution and I'm still running into an issue and cannot seems to figure it out, I'm using zsh, and when I use your fix I get this error: /bin/sh: rvm: command not found. I wonder if anyone has an idea,
Thanks for the help
Update: in the end a reboot of the computer fixed it.
The VSCode Rubocop extension should be using the current project's rvm/ruby version instead of the system default. The extension should be utilizing the same dependencies as the current project.
Not sure if #23 is related
Problem
When you are using something like
rubocop-rspec
it will install to the project's ruby version, but the rubocop extension will not have access to the correct dependant gems because it's using a different version that doesn't have that gem installed.Error Codes
When the extension tries to run I see something like this pop up: