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

Visual Studio Code 0.7.4 appears to be unable to initialize rbenv #2202

Open
justinbburris opened this issue Jun 18, 2024 · 6 comments · May be fixed by #2239
Open

Visual Studio Code 0.7.4 appears to be unable to initialize rbenv #2202

justinbburris opened this issue Jun 18, 2024 · 6 comments · May be fixed by #2239
Assignees
Labels
bug Something isn't working

Comments

@justinbburris
Copy link

justinbburris commented Jun 18, 2024

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 justinbburris added the bug Something isn't working label Jun 18, 2024
@vinistock
Copy link
Member

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?

@justinbburris
Copy link
Author

justinbburris commented Jun 20, 2024

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?

@vinistock
Copy link
Member

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

@xeron
Copy link

xeron commented Jul 1, 2024

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

@vinistock
Copy link
Member

@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.

@xeron
Copy link

xeron commented Jul 2, 2024

@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 – #2247

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants