ruby-lsp icon indicating copy to clipboard operation
ruby-lsp copied to clipboard

Visual Studio Code 0.7.4 appears to be unable to initialize rbenv

Open justinbburris opened this issue 1 year ago • 6 comments

Description

When I attempt to load a codebase with ruby LSP and the Visual Studio Code integration (at version 0.7.4), the extension fails to load.

It works when using the extension at 0.7.2

Some initial investigation turned up this change to the rbenv (and other manager) initialization. Seems like it could be related?

Error

VS Code error popup

Automatic Ruby environment activation with rbenv failed: 
Command failed: rbenv exec ruby -W0 -rjson -e 'STDERR.print({env: ENV.to_h,yjit:!!defined?(RubyVM::YJIT),version:RUBY_VERSION}.to_json)' 
zsh:1: command not found: rbenv

Output error

2024-06-17 21:25:52.034 [info] (smallwins) Running command: `rbenv exec ruby -W0 -rjson -e 'STDERR.print({env: ENV.to_h,yjit:!!defined?(RubyVM::YJIT),version:RUBY_VERSION}.to_json)'` in /Users/justinburris/dev/saishori/smallwins using shell: /bin/zsh

Debugging

Here's the output from running the intialization command from the shell directly

$ /bin/zsh -ic 'rbenv exec ruby -rjson -e "puts JSON.dump(ENV.to_h)"'

{"RBENV_VERSION":"3.3.0",...}

Reproduction steps

Configuration

Processor: Apple M2 Max ruby version: 3.3.0 & 3.0.3 rbenv version: 1.2.0 (installed via brew and configured per usual method) shell: zsh editor: VS Code 1.90.1 No vs code configuration

Project setup

Any ruby project with a Gemfile that has the ruby-lsp gem

If it helps, here's a snippet of my .zshrc

eval "$(/opt/homebrew/bin/brew shellenv)"

# rbenv
# To enable shims and autocompletion add to your profile:
eval "$(rbenv init - zsh)"
FPATH=~/.rbenv/completions:"$FPATH"

justinbburris avatar Jun 18 '24 01:06 justinbburris

Thank you for the bug report! We recently pushed changes to decouple Ruby environment activation from shells as much as possible because it caused headaches for a number of users.

I suspect the reason for not finding rbenv is because it's only present if you source ~/.zshrc, which we don't do by default.

If you source rbenv in your profile file (whatever the zsh equivalent of .profile is), does it work?

vinistock avatar Jun 20 '24 13:06 vinistock

I appreciate y'alls work here. It's tough dealing with all of the different configurations out there.

It looks like moving it to the ~/.zshenv file did the trick!

Per these docs, that file is sourced very early in the initialization, and appears to work!

Would y'all be open to me updating the troubleshooting guide to indicate this solution?

justinbburris avatar Jun 20 '24 14:06 justinbburris

Yes, definitely! We should include that in the documentation.

vinistock avatar Jun 20 '24 17:06 vinistock

I see similar issues activating asdf if vscode was not started from the shell.

xeron avatar Jul 01 '24 02:07 xeron

@xeron that's a bit surprising to me since we search for the asdf script file and manually source it to ensure it's available before invoking it.

Do you want to create a separate issue for that and describe your exact setup? It seems like a different issue related only to ASDF integration.

vinistock avatar Jul 02 '24 17:07 vinistock

@xeron that's a bit surprising to me since we search for the asdf script file and manually source it to ensure it's available before invoking it.

Do you want to create a separate issue for that and describe your exact setup? It seems like a different issue related only to ASDF integration.

I think you're right, I created a new issue – https://github.com/Shopify/ruby-lsp/issues/2247

xeron avatar Jul 02 '24 21:07 xeron

It seems @justinbburris's issue is solved, and there is a seperate issue by @xeron, so I will close this.

andyw8 avatar Jul 25 '24 19:07 andyw8