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

Indicate zshenv is to be used when configuring ZSH version managers #2239

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
19 changes: 15 additions & 4 deletions TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ with the same Ruby version as your projects, we need to properly set these envir
invoking your Ruby version manager.

The extension runs a command using your shell's interactive mode, so that version managers configured in files such as
`~/.zshrc` are picked up automatically. The command then exports the environment information into JSON, so that we can
`~/.zshenv` are picked up automatically. The command then exports the environment information into JSON, so that we can
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a zsh user. Does this file always exist? Or could there be users that don't have this file and only have ~/.zshrc?

I'm trying to understand if this is a recommendation that would work for everyone or if it might require extra steps.

Copy link

Choose a reason for hiding this comment

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

I think it's dependent of your ZSH setup. I run ZSH with Prezto. My ruby is sourced in ~/.zshrc with Mise and it works. So i'm not sure the doc change cover all cases.

Copy link
Author

Choose a reason for hiding this comment

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

@vinistock I created this file when testing this functionality.

@louim I attempted to source from ~/.zshrc and it failed to initialize. :/

Copy link

Choose a reason for hiding this comment

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

@justinbburris strange, rbenv init will either write itself to ~/.zshrc or ~/.zprofile: https://github.com/rbenv/rbenv/blob/3bac268cdb81dd745ce13a1cf6ff4a286336ab3b/libexec/rbenv-init#L115-L124. Maybe something else on your setup is interfering with rbenv?

Copy link

@louim louim Jul 8, 2024

Choose a reason for hiding this comment

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

This (somewhat old) blog post explain in which order ZSH load files: https://shreevatsa.wordpress.com/2008/03/30/zshbash-startup-files-loading-order-bashrc-zshrc-etc/. ~/.zshrc should always be loaded, either in login or non-login mode.

inject it into the NodeJS process and appropriately set the Ruby version and gem installation paths.

As an example, the activation script for `zsh` using `rbenv` as a version manager will look something like this:

```shell
# Invoke zsh using interactive mode (loads ~/.zshrc) to run a single command
# Invoke zsh using interactive mode (loads ~/.zshenv) to run a single command
# The command is `rbenv exec ruby`, which automatically sets all relevant environment variables and selects the
# specified Ruby version
# We then print the activated environment as JSON. We read that JSON from the NodeJS process to insert the needed
# environment variables in order to run Ruby correctly
/bin/zsh -ic 'rbenv exec ruby -rjson -e "puts JSON.dump(ENV.to_h)"'
/bin/zsh -c 'rbenv exec ruby -rjson -e "puts JSON.dump(ENV.to_h)"'
```

After activating the Ruby version, we then proceed to boot the server gem (`ruby-lsp`). To avoid having users include
Expand All @@ -40,7 +40,7 @@ There are two main sources of issues users typically face during activation: she

### Shell issues

When the extension invokes the shell and loads its config file (`~/.zshrc`, `~/.bashrc`, etc), it is susceptible to
When the extension invokes the shell and loads its config file (`~/.zshenv`, `~/.bashrc`, etc), it is susceptible to
issues that may be caused by how the shell or its plugins interact with the NodeJS process. For example

- Some plugins completely redirect the stderr pipe to implement their functionality (fixed on the Ruby LSP side by
Expand All @@ -58,6 +58,17 @@ this problem, please try to

More context about this issue on https://github.com/Shopify/vscode-ruby-lsp/issues/901.

#### ZSH configuration

If you use zsh, then make sure to configure your version in your ZSH env file (`~/.zshenv`).

```shell
# ~/.zshenv
if [[ -o rcs ]]; then
eval "$(rbenv init - zsh)"
fi
```

### Bundler issues

If the extension successfully activated the Ruby environment, it may still fail when trying to compose the custom bundle
Expand Down
2 changes: 1 addition & 1 deletion vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ by clicking `Change version manager` in the language status center or by changin
```

To make sure that the Ruby LSP can find the version manager scripts, make sure that they are loaded in the shell's
configuration script (e.g.: ~/.bashrc, ~/.zshrc) and that the SHELL environment variable is set and pointing to the
configuration script (e.g.: ~/.bashrc, ~/.zshenv) and that the SHELL environment variable is set and pointing to the
default shell.

> [!NOTE]
Expand Down
Loading