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

Activate Ruby environment using version managers #113

Merged
merged 1 commit into from
Mar 25, 2023

Conversation

vinistock
Copy link
Contributor

Closes #21

Add Ruby environment activation through version managers. This PR

  • Exposes a new configuration to select a version manager
  • Implements how to activate the Ruby environment based on each manager
  • Starts activating the environment before trying to run the rdbg executable

@vinistock vinistock force-pushed the vs/introduce_ruby_version_managers branch from ad16140 to 12172dc Compare January 18, 2023 19:49
@vinistock vinistock marked this pull request as ready for review January 18, 2023 20:35
@ko1
Copy link
Collaborator

ko1 commented Feb 14, 2023

Sorry I forget to response on it.

(1) do you plan to make a npm package for it?
(2) For "none" I think it is enough to use injectRubyEnvironment without rbenv (and so on) is enough (and remove all other shell dependent code), at least on rbenv. What do you think about it? In other words, I don't want to ask setting rdbg.rubyVersionManager if not needed.

@ko1
Copy link
Collaborator

ko1 commented Feb 14, 2023

Another question.

On rbenv, RBENV_VERSION is specified at first setting. if .ruby-version is rewritten, it seems it doesn't applied for VSCode without restarting the VSCode process. Is it intentional? I'm not sure how often such a case happened.

@vinistock vinistock force-pushed the vs/introduce_ruby_version_managers branch from 12172dc to 8efa22d Compare February 14, 2023 16:02
@vinistock
Copy link
Contributor Author

I've rebased the PR and modified the changes in #124, since we want all shells to use interactive mode to load rbenv, chruby or any other manager.

Concerning your questions

  1. Yes, we hope to turn the activation into a package so that we don't have to keep duplicating code between the Ruby LSP, RDBG and any other extension that wants to launch Ruby
  2. I'm not sure I understand this one. When the version manager is none (which is the default), we don't invoke injectRubyEnvironment
  3. If you want to re-activate the Ruby environment and inject the variables into the node process when .ruby-version changes, then we have to use a VS Code file watcher to track changes to the file and then trigger re-activation if any modifications happen

@ko1
Copy link
Collaborator

ko1 commented Feb 20, 2023

Thank you for your quick reply.

Yes, we hope to turn the activation into a package so that we don't have to keep duplicating code between the Ruby LSP, RDBG and any other extension that wants to launch Ruby

If it will be released soon, I want to wait for it.

I'm not sure I understand this one. When the version manager is none (which is the default), we don't invoke injectRubyEnvironment

Yes. My idea is "assuming users use rbenv and injectRubyEnvironment for none will setup rbenv environment variables and no need to call shell for the following commands. But it has an issue for (3).

If you want to re-activate the Ruby environment and inject the variables into the node process when .ruby-version changes, then we have to use a VS Code file watcher to track changes to the file and then trigger re-activation if any modifications happen

I understand the technique. My question was it is intentional or not for .ruby-version changes. As I wrote " I'm not sure how often such a case happened." so if the real case is not many, I agree we can ignore it.

@vinistock vinistock force-pushed the vs/introduce_ruby_version_managers branch 2 times, most recently from 7c6c7e1 to f136729 Compare February 21, 2023 20:45
@vinistock
Copy link
Contributor Author

If it will be released soon, I want to wait for it.

Unfortunately, we're not going to be able to work on it immediately. I would recommend merging this for now to make it work on any version manager and then we can refactor once the NPM package is released.

Yes. My idea is "assuming users use rbenv and injectRubyEnvironment for none will setup rbenv environment variables and no need to call shell for the following commands. But it has an issue for (3).

The other managers have a lot of users as well - in particular asdf and chruby. For our team, shadowenv is extremely important given that it is the one we use in every project. I don't think we can escape using shell commands if we want to support a variety of managers and make sure the extension works for all Ruby developers.

I understand the technique. My question was it is intentional or not for .ruby-version changes. As I wrote " I'm not sure how often such a case happened." so if the real case is not many, I agree we can ignore it.

I pushed another commit adding a file watcher. I think it's worth supporting the case of updating .ruby-version, Gemfile and Gemfile.lock. It's probably fairly common.

src/extension.ts Outdated
Comment on lines 275 to 355
switch (true) {
case shell && (shell.endsWith("bash") || shell.endsWith("fish")):
return shell + " -l -c '" + cmd + "'";
case shell && shell.endsWith("zsh"):
// As the recommended way, initialization commands for rbenv are written in ".zshrc".
// However, it's not loaded on the non-interactive shell.
// Thus, we need to run this command as the interactive shell.
// FYI: https://zsh.sourceforge.io/Guide/zshguide02.html
return shell + " -l -c -i '" + cmd + "'";
default:
return cmd;

if (this.support_login(shell)) {
return shell + " -lic '" + cmd + "'";
} else {
return cmd;
Copy link
Member

@ono-max ono-max Mar 1, 2023

Choose a reason for hiding this comment

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

Can you cut out this part to another PR? I can merge it soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not merge this PR instead?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I can't merge this PR since @ko1-san is reviewing this PR, and he decides it. And the reason why I ask you to cut this part to another PR is that it is significant to merge this part regardless of this feature.

Copy link
Member

Choose a reason for hiding this comment

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

But, it's just a suggestion, I'll leave it up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand your point of view, but my sincere opinion is that we should focus on getting this PR merged.

Using Ruby version managers is common practice on the community and making sure the environment is activated properly is essential to get all of the benefits of RDBG in the editor.

@ko1
Copy link
Collaborator

ko1 commented Mar 7, 2023

I think no configuration is better but I feel current proposed documentation asks user to write it if they uses a version manager. So I want to rewrite it after merge.
@vinistock could you allow me to modify them after merging?

@vinistock
Copy link
Contributor Author

Can you clarify what you mean by no configuration? Do you mean trying to guess which version manager the developer uses?

Totally okay with you refactoring as needed. Just trying to understand your perspective since the long term vision is for the Ruby LSP and RDBG to both use an NPM package for Ruby environment activation.

@vinistock vinistock force-pushed the vs/introduce_ruby_version_managers branch from f136729 to 037c575 Compare March 9, 2023 21:30
@vinistock
Copy link
Contributor Author

We're adding the auto option as the default for the Ruby LSP, which automatically detects the user's version manager. Would that what you're thinking about?

@ko1
Copy link
Collaborator

ko1 commented Mar 22, 2023

@vinistock
Sorry for the late response but it seems conflicting.
Could you rebase it or can I make a patch?

@vinistock vinistock force-pushed the vs/introduce_ruby_version_managers branch from 037c575 to 581d3a0 Compare March 22, 2023 13:56
@vinistock
Copy link
Contributor Author

I rebased. Let me know if you want to include the auto option. We've been using it in the Ruby LSP and it's very convenient to avoid configuration.

@firien
Copy link
Contributor

firien commented Mar 25, 2023

promisify was removed with #41. I have nothing against promisify - it was really the embedded require that caught my eye and provided impetus for e1040ba.
For consistency, I think this should adopt the Promise wrapped callback style, or #41 should revert to promisify version. As noted in #41 - there are also event based versions of child_process.exec in here - so this would introduce yet another flavor of child_process.exec

@ono-max
Copy link
Member

ono-max commented Mar 25, 2023

Thanks @firien san.

I'm ok with using promisify, so let's use promisify in #41, in another PR.

@ko1 ko1 merged commit 69de9ea into ruby:master Mar 25, 2023
@vinistock vinistock deleted the vs/introduce_ruby_version_managers branch March 27, 2023 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Can't launch debugger for Rails project with Rbenv.
4 participants